Skip to content

Commit

Permalink
Require EDPMServiceType
Browse files Browse the repository at this point in the history
This change switches EDPMServiceType from optional to required.
Since the EDPMServiceType of custom services needs to match that of an existing service,
we also remove the defaulting mechanism in the webhook.

Signed-off-by: Brendan Shephard <bshephar@redhat.com>
  • Loading branch information
bshephar committed Nov 8, 2024
1 parent 5637f8d commit 44af400
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 15 deletions.
1 change: 1 addition & 0 deletions apis/dataplane/v1beta1/openstackdataplaneservice_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ type OpenStackDataPlaneServiceSpec struct {
// corresponds to the ansible role name (without the "edpm_" prefix) used
// to manage the service. If not set, will default to the
// OpenStackDataPlaneService name.
// +kubebuilder:validation:Required
EDPMServiceType string `json:"edpmServiceType,omitempty" yaml:"edpmServiceType,omitempty"`
}

Expand Down
8 changes: 0 additions & 8 deletions apis/dataplane/v1beta1/openstackdataplaneservice_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,9 @@ var _ webhook.Defaulter = &OpenStackDataPlaneService{}
func (r *OpenStackDataPlaneService) Default() {

openstackdataplaneservicelog.Info("default", "name", r.Name)
r.Spec.Default(r.Name)
r.DefaultLabels()
}

// Default - set defaults for this OpenStackDataPlaneService
func (spec *OpenStackDataPlaneServiceSpec) Default(name string) {
if spec.EDPMServiceType == "" {
spec.EDPMServiceType = name
}
}

// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
// +kubebuilder:webhook:path=/validate-dataplane-openstack-org-v1beta1-openstackdataplaneservice,mutating=false,failurePolicy=fail,sideEffects=None,groups=dataplane.openstack.org,resources=openstackdataplaneservices,verbs=create;update,versions=v1beta1,name=vopenstackdataplaneservice.kb.io,admissionReviewVersions=v1

Expand Down
2 changes: 1 addition & 1 deletion docs/assemblies/proc_creating-a-custom-service.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ spec:
deployOnAllNodeSets: true
----

. Optional: Specify the `edpmServiceType` field for the service. Different custom services may use the same ansible content to manage the same EDPM service (such as `ovn` or `nova`). The `DataSources`, TLS certificates, and CA certificates need to be mounted at the same locations so they can be found by the ansible content even when using a custom service. `edpmServiceType` is used to create this association. The value is the name of the default service that uses the same ansible content as the custom service. If there are multiple services with the same `edpmServiceType` listed in a nodeset or deployment spec, latter ones would be ignored.
. Required: Specify the `edpmServiceType` field for the service. Different custom services may use the same ansible content to manage the same EDPM service (such as `ovn` or `nova`). The `DataSources`, TLS certificates, and CA certificates need to be mounted at the same locations so they can be found by the ansible content even when using a custom service. `edpmServiceType` is used to create this association. The value is the name of the default service that uses the same ansible content as the custom service. If there are multiple services with the same `edpmServiceType` listed in a nodeset or deployment spec, latter ones would be ignored.
+
For example, a custom service that uses the `edpm_ovn` ansible content from `edpm-ansible` would set `edpmServiceType` to `ovn`, which matches the default `ovn` service name provided by `openstack-operator`.
+
Expand Down
7 changes: 6 additions & 1 deletion tests/functional/dataplane/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,11 @@ func DefaultDataplaneService(name types.NamespacedName) map[string]interface{} {
"metadata": map[string]interface{}{
"name": name.Name,
"namespace": name.Namespace,
}}
},
"spec": map[string]interface{}{
"edpmServiceType": "notGlobal",
},
}
}

// Create an empty OpenStackDataPlaneService struct
Expand All @@ -531,6 +535,7 @@ func DefaultDataplaneGlobalService(name types.NamespacedName) map[string]interfa
},
"spec": map[string]interface{}{
"deployOnAllNodeSets": true,
"edpmServiceType": "global",
},
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ var _ = Describe("Dataplane Deployment Test", func() {
CreateDataplaneService(dataplaneServiceName, false)
CreateDataplaneService(dataplaneGlobalServiceName, true)
CreateDataPlaneServiceFromSpec(dataplaneUpdateServiceName, map[string]interface{}{
"edpmServiceType": "foo-update-service",
"edpmServiceType": "update",
"openStackAnsibleEERunnerImage": "foo-image:latest"})

DeferCleanup(th.DeleteService, dataplaneServiceName)
Expand Down Expand Up @@ -750,7 +750,7 @@ var _ = Describe("Dataplane Deployment Test", func() {
CreateDataplaneService(dataplaneServiceName, false)
CreateDataplaneService(dataplaneGlobalServiceName, true)
CreateDataPlaneServiceFromSpec(dataplaneUpdateServiceName, map[string]interface{}{
"EDPMServiceType": "foo-update-service"})
"edpmServiceType": "foo-update-service"})

DeferCleanup(th.DeleteService, dataplaneServiceName)
DeferCleanup(th.DeleteService, dataplaneGlobalServiceName)
Expand Down Expand Up @@ -1081,7 +1081,7 @@ var _ = Describe("Dataplane Deployment Test", func() {
CreateDataplaneService(dataplaneServiceName, false)
CreateDataplaneService(dataplaneGlobalServiceName, true)
CreateDataPlaneServiceFromSpec(dataplaneUpdateServiceName, map[string]interface{}{
"EDPMServiceType": "foo-update-service"})
"edpmServiceType": "foo-update-service"})

DeferCleanup(th.DeleteService, dataplaneServiceName)
DeferCleanup(th.DeleteService, dataplaneGlobalServiceName)
Expand Down Expand Up @@ -1288,7 +1288,7 @@ var _ = Describe("Dataplane Deployment Test", func() {
CreateDataplaneService(dataplaneServiceName, false)
CreateDataplaneService(dataplaneGlobalServiceName, true)
CreateDataPlaneServiceFromSpec(dataplaneUpdateServiceName, map[string]interface{}{
"EDPMServiceType": "foo-update-service"})
"edpmServiceType": "foo-update-service"})

DeferCleanup(th.DeleteService, dataplaneServiceName)
DeferCleanup(th.DeleteService, dataplaneGlobalServiceName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1358,7 +1358,8 @@ var _ = Describe("Dataplane NodeSet Test", func() {

dataplanev1.SetupDefaults()
updateServiceSpec := map[string]interface{}{
"playbook": "osp.edpm.update",
"playbook": "osp.edpm.update",
"edpmServiceType": "update",
}
CreateDataPlaneServiceFromSpec(dataplaneUpdateServiceName, updateServiceSpec)
DeferCleanup(th.DeleteService, dataplaneUpdateServiceName)
Expand Down

0 comments on commit 44af400

Please sign in to comment.