diff --git a/apis/bases/core.openstack.org_openstackcontrolplanes.yaml b/apis/bases/core.openstack.org_openstackcontrolplanes.yaml index 2e422fae9..669280c40 100644 --- a/apis/bases/core.openstack.org_openstackcontrolplanes.yaml +++ b/apis/bases/core.openstack.org_openstackcontrolplanes.yaml @@ -10879,6 +10879,10 @@ spec: format: int32 minimum: 0 type: integer + nodeSelector: + additionalProperties: + type: string + type: object override: properties: service: @@ -14703,6 +14707,10 @@ spec: templates: additionalProperties: properties: + nodeSelector: + additionalProperties: + type: string + type: object replicas: default: 1 format: int32 @@ -14859,6 +14867,10 @@ spec: items: type: string type: array + nodeSelector: + additionalProperties: + type: string + type: object storageClass: default: "" type: string @@ -14881,6 +14893,10 @@ spec: items: type: string type: array + nodeSelector: + additionalProperties: + type: string + type: object override: properties: service: @@ -14986,6 +15002,10 @@ spec: format: int64 minimum: 1 type: integer + nodeSelector: + additionalProperties: + type: string + type: object partPower: default: 10 format: int64 @@ -15022,6 +15042,10 @@ spec: items: type: string type: array + nodeSelector: + additionalProperties: + type: string + type: object replicas: default: 1 format: int32 @@ -15462,6 +15486,10 @@ spec: items: type: string type: array + nodeSelector: + additionalProperties: + type: string + type: object override: properties: service: @@ -15556,7 +15584,6 @@ spec: type: object required: - databaseInstance - - memcachedInstance - secret type: object enabled: @@ -15614,6 +15641,10 @@ spec: items: type: string type: array + nodeSelector: + additionalProperties: + type: string + type: object passwordSelector: default: ceilometerService: CeilometerPassword @@ -16340,6 +16371,10 @@ spec: type: string type: object type: object + nodeSelector: + additionalProperties: + type: string + type: object type: object type: object tls: diff --git a/apis/client/v1beta1/openstackclient_types.go b/apis/client/v1beta1/openstackclient_types.go index 9c6a12fa9..f2e044574 100644 --- a/apis/client/v1beta1/openstackclient_types.go +++ b/apis/client/v1beta1/openstackclient_types.go @@ -49,8 +49,8 @@ type OpenStackClientSpecCore struct { OpenStackConfigSecret *string `json:"openStackConfigSecret"` // +kubebuilder:validation:Optional - // NodeSelector to target subset of worker nodes running control plane services (currently only applies to KeystoneAPI and PlacementAPI) - NodeSelector map[string]string `json:"nodeSelector,omitempty"` + // NodeSelector to target subset of worker nodes + NodeSelector *map[string]string `json:"nodeSelector,omitempty"` // +kubebuilder:validation:Optional // +operator-sdk:csv:customresourcedefinitions:type=spec diff --git a/apis/client/v1beta1/zz_generated.deepcopy.go b/apis/client/v1beta1/zz_generated.deepcopy.go index 2cc8c40c9..010dfef40 100644 --- a/apis/client/v1beta1/zz_generated.deepcopy.go +++ b/apis/client/v1beta1/zz_generated.deepcopy.go @@ -131,9 +131,13 @@ func (in *OpenStackClientSpecCore) DeepCopyInto(out *OpenStackClientSpecCore) { } if in.NodeSelector != nil { in, out := &in.NodeSelector, &out.NodeSelector - *out = make(map[string]string, len(*in)) - for key, val := range *in { - (*out)[key] = val + *out = new(map[string]string) + if **in != nil { + in, out := *in, *out + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } } } out.Ca = in.Ca diff --git a/apis/core/v1beta1/openstackcontrolplane_types.go b/apis/core/v1beta1/openstackcontrolplane_types.go index 54db1050f..6add4f982 100644 --- a/apis/core/v1beta1/openstackcontrolplane_types.go +++ b/apis/core/v1beta1/openstackcontrolplane_types.go @@ -86,7 +86,7 @@ type OpenStackControlPlaneSpec struct { // +kubebuilder:validation:Optional // +operator-sdk:csv:customresourcedefinitions:type=spec - // NodeSelector to target subset of worker nodes running control plane services (currently only applies to KeystoneAPI and PlacementAPI) + // NodeSelector to target subset of worker nodes running control plane services NodeSelector map[string]string `json:"nodeSelector,omitempty"` // +kubebuilder:validation:Optional @@ -507,6 +507,10 @@ type RabbitmqTemplate struct { // +operator-sdk:csv:customresourcedefinitions:type=spec // Overrides to use when creating the Rabbitmq clusters rabbitmqv2.RabbitmqClusterSpecCore `json:",inline"` + // +kubebuilder:validation:Optional + // +operator-sdk:csv:customresourcedefinitions:type=spec + // NodeSelector to target subset of worker nodes running this service + NodeSelector *map[string]string `json:"nodeSelector,omitempty"` } // OvnSection defines the desired state of OVN services diff --git a/apis/core/v1beta1/zz_generated.deepcopy.go b/apis/core/v1beta1/zz_generated.deepcopy.go index 6b7938f14..9e3ebff7c 100644 --- a/apis/core/v1beta1/zz_generated.deepcopy.go +++ b/apis/core/v1beta1/zz_generated.deepcopy.go @@ -1470,6 +1470,17 @@ func (in *RabbitmqSection) DeepCopy() *RabbitmqSection { func (in *RabbitmqTemplate) DeepCopyInto(out *RabbitmqTemplate) { *out = *in in.RabbitmqClusterSpecCore.DeepCopyInto(&out.RabbitmqClusterSpecCore) + if in.NodeSelector != nil { + in, out := &in.NodeSelector, &out.NodeSelector + *out = new(map[string]string) + if **in != nil { + in, out := *in, *out + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RabbitmqTemplate. diff --git a/apis/go.mod b/apis/go.mod index ea3c1c380..d19a17748 100644 --- a/apis/go.mod +++ b/apis/go.mod @@ -13,21 +13,21 @@ require ( github.com/openstack-k8s-operators/glance-operator/api v0.5.1-0.20241120062804-89e9fe93e886 github.com/openstack-k8s-operators/heat-operator/api v0.5.1-0.20241120140156-1c476cfe7c63 github.com/openstack-k8s-operators/horizon-operator/api v0.5.1-0.20241119161147-c38568cb3fb0 - github.com/openstack-k8s-operators/infra-operator/apis v0.5.1-0.20241118112815-d52a058b34a8 - github.com/openstack-k8s-operators/ironic-operator/api v0.5.1-0.20241114211630-5b4dcbed9b37 + github.com/openstack-k8s-operators/infra-operator/apis v0.5.1-0.20241120235143-b225194fd0fd + github.com/openstack-k8s-operators/ironic-operator/api v0.5.1-0.20241120225637-63d25e2bf291 github.com/openstack-k8s-operators/keystone-operator/api v0.5.1-0.20241119162247-18b741090348 github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20241114091812-6dc9fd0961dc github.com/openstack-k8s-operators/lib-common/modules/storage v0.5.1-0.20241114091812-6dc9fd0961dc - github.com/openstack-k8s-operators/manila-operator/api v0.5.1-0.20241117150431-21b7f58d9ddf + github.com/openstack-k8s-operators/manila-operator/api v0.5.1-0.20241121093406-bfd56f125086 github.com/openstack-k8s-operators/mariadb-operator/api v0.5.1-0.20241120160542-4b457715f74e - github.com/openstack-k8s-operators/neutron-operator/api v0.5.1-0.20241114104932-eae3f8cd032b + github.com/openstack-k8s-operators/neutron-operator/api v0.5.1-0.20241121095318-591a3bcbcda6 github.com/openstack-k8s-operators/nova-operator/api v0.5.1-0.20241119125634-42b7b8417b48 - github.com/openstack-k8s-operators/octavia-operator/api v0.5.1-0.20241115111947-2336829c2d73 + github.com/openstack-k8s-operators/octavia-operator/api v0.5.1-0.20241121093935-bc64ab6db016 github.com/openstack-k8s-operators/openstack-baremetal-operator/api v0.5.1-0.20241118111717-a1d460a6d81f - github.com/openstack-k8s-operators/ovn-operator/api v0.5.1-0.20241118072048-45d5df9ad730 + github.com/openstack-k8s-operators/ovn-operator/api v0.5.1-0.20241121095319-a34ad51b8446 github.com/openstack-k8s-operators/placement-operator/api v0.5.1-0.20241119131546-e4c1ba679d22 - github.com/openstack-k8s-operators/swift-operator/api v0.5.1-0.20241114094619-107d1aac9458 - github.com/openstack-k8s-operators/telemetry-operator/api v0.5.1-0.20241118203716-9550c8740911 + github.com/openstack-k8s-operators/swift-operator/api v0.5.1-0.20241121093118-6ab57de4e6cc + github.com/openstack-k8s-operators/telemetry-operator/api v0.5.1-0.20241121100420-f2c8dd9aa6c3 github.com/rabbitmq/cluster-operator/v2 v2.11.0 github.com/rhobs/obo-prometheus-operator/pkg/apis/monitoring v0.71.0-rhobs1 // indirect github.com/rhobs/observability-operator v0.3.1 // indirect diff --git a/apis/go.sum b/apis/go.sum index 12db59525..619449aed 100644 --- a/apis/go.sum +++ b/apis/go.sum @@ -106,10 +106,10 @@ github.com/openstack-k8s-operators/heat-operator/api v0.5.1-0.20241120140156-1c4 github.com/openstack-k8s-operators/heat-operator/api v0.5.1-0.20241120140156-1c476cfe7c63/go.mod h1:PuXjq4bV3/mYo4OAD/4tTon0N7E9YYXZHWiZLeZFVek= github.com/openstack-k8s-operators/horizon-operator/api v0.5.1-0.20241119161147-c38568cb3fb0 h1:YtC+hqGKx9M8B6fHgA1eFlq1yjEiOWwp1zZqyFtjSbA= github.com/openstack-k8s-operators/horizon-operator/api v0.5.1-0.20241119161147-c38568cb3fb0/go.mod h1:ezxV+6xd12IRKespGaDlJCUQ301yxrBlQUCEbeYQgSA= -github.com/openstack-k8s-operators/infra-operator/apis v0.5.1-0.20241118112815-d52a058b34a8 h1:mmnunGX3tnIT4ErxFjYcKb38VLjnfe9JcIcU9LaW9rE= -github.com/openstack-k8s-operators/infra-operator/apis v0.5.1-0.20241118112815-d52a058b34a8/go.mod h1:6x5zgJJBjrOhsTtNALYrM2ecUH92kIoZbZ6w1fKHPfs= -github.com/openstack-k8s-operators/ironic-operator/api v0.5.1-0.20241114211630-5b4dcbed9b37 h1:k++YKQetyZqG6t+kWLhVUclgwLRKspCEyxeEWCeDgjM= -github.com/openstack-k8s-operators/ironic-operator/api v0.5.1-0.20241114211630-5b4dcbed9b37/go.mod h1:nKeZBXFCwbYxTpIW9mPs/SK+4cODkEZgs+yOytvafBo= +github.com/openstack-k8s-operators/infra-operator/apis v0.5.1-0.20241120235143-b225194fd0fd h1:6LmBamNQRwX76TiR+qo7Ejkb5bT2IPFhstkTWtVh7m4= +github.com/openstack-k8s-operators/infra-operator/apis v0.5.1-0.20241120235143-b225194fd0fd/go.mod h1:6x5zgJJBjrOhsTtNALYrM2ecUH92kIoZbZ6w1fKHPfs= +github.com/openstack-k8s-operators/ironic-operator/api v0.5.1-0.20241120225637-63d25e2bf291 h1:wK/7eRfMI4bJxqC4NFRdNJKPL9CPf5gSQHNsn2EfqIc= +github.com/openstack-k8s-operators/ironic-operator/api v0.5.1-0.20241120225637-63d25e2bf291/go.mod h1:nKeZBXFCwbYxTpIW9mPs/SK+4cODkEZgs+yOytvafBo= github.com/openstack-k8s-operators/keystone-operator/api v0.5.1-0.20241119162247-18b741090348 h1:mJeXL6JpNWe7d8wA8UZ1EI5T70f8HIgE2ecNjfPFIq4= github.com/openstack-k8s-operators/keystone-operator/api v0.5.1-0.20241119162247-18b741090348/go.mod h1:AZhHY6dZzGyG9iVOf1poD7pTS9c7ZG/f99Fg+GdFVEk= github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20241114091812-6dc9fd0961dc h1:Ufa/q/nC9wmKblvsc0kJppsXHOJoY4fbUamb3ItWCOk= @@ -118,28 +118,28 @@ github.com/openstack-k8s-operators/lib-common/modules/openstack v0.5.1-0.2024111 github.com/openstack-k8s-operators/lib-common/modules/openstack v0.5.1-0.20241114091812-6dc9fd0961dc/go.mod h1:IASoGvp5QM/tBJUd/8i8uIjj4DBnI+64Ydh4r7pmnvA= github.com/openstack-k8s-operators/lib-common/modules/storage v0.5.1-0.20241114091812-6dc9fd0961dc h1:J5Kr0/ST3KqMzSRhcubr0fF9/vWzma+U63P9kfmgIA8= github.com/openstack-k8s-operators/lib-common/modules/storage v0.5.1-0.20241114091812-6dc9fd0961dc/go.mod h1:tfgBeLRqmlH/NQkLPe7396rj+t0whv2wPuMb8Ttvh8w= -github.com/openstack-k8s-operators/manila-operator/api v0.5.1-0.20241117150431-21b7f58d9ddf h1:UsAefjZBqFl0dYMg/efe75ECm8cAwc/2FCEBPYjQfIY= -github.com/openstack-k8s-operators/manila-operator/api v0.5.1-0.20241117150431-21b7f58d9ddf/go.mod h1:0/qgnjufYIqe439/3aUU/cwnjDwdUlNR3jnRubLTD5o= +github.com/openstack-k8s-operators/manila-operator/api v0.5.1-0.20241121093406-bfd56f125086 h1:83nj2btbl2i06eJHtZdudyj0r1uuFqkorwkLdgssfp0= +github.com/openstack-k8s-operators/manila-operator/api v0.5.1-0.20241121093406-bfd56f125086/go.mod h1:0/qgnjufYIqe439/3aUU/cwnjDwdUlNR3jnRubLTD5o= github.com/openstack-k8s-operators/mariadb-operator/api v0.5.1-0.20241120160542-4b457715f74e h1:id6qqUWUMo0h7LoIhjQlMIjy4iihoBCi7Pe/jWjKHcY= github.com/openstack-k8s-operators/mariadb-operator/api v0.5.1-0.20241120160542-4b457715f74e/go.mod h1:348EPtAdpE2LxHAH4bHdCMNP7HyX6DevwEsF9DQ0S2k= -github.com/openstack-k8s-operators/neutron-operator/api v0.5.1-0.20241114104932-eae3f8cd032b h1:JMMPYDierS4YZdG9O/50kLihPQqmDz7p72btLy7Ibew= -github.com/openstack-k8s-operators/neutron-operator/api v0.5.1-0.20241114104932-eae3f8cd032b/go.mod h1:Kfuu3g4PSFpEowdWhbnTgSlDpsBGswQf/WU/kKQKK7s= +github.com/openstack-k8s-operators/neutron-operator/api v0.5.1-0.20241121095318-591a3bcbcda6 h1:ZFsA5wQwdITdXQxX99heejR9mWWsy8eGAaUoORk1pQI= +github.com/openstack-k8s-operators/neutron-operator/api v0.5.1-0.20241121095318-591a3bcbcda6/go.mod h1:Kfuu3g4PSFpEowdWhbnTgSlDpsBGswQf/WU/kKQKK7s= github.com/openstack-k8s-operators/nova-operator/api v0.5.1-0.20241119125634-42b7b8417b48 h1:eCvn/lCMqWTvlN74nFr7nG2EvZdvJPdSR9Ts2eTaM6c= github.com/openstack-k8s-operators/nova-operator/api v0.5.1-0.20241119125634-42b7b8417b48/go.mod h1:330SfEZuqG3b90HopY+Hk90y0OTyPcBa0GRKPUD7BHE= -github.com/openstack-k8s-operators/octavia-operator/api v0.5.1-0.20241115111947-2336829c2d73 h1:HWHbtCBbTv3zvluSpV4ZG8Ov0VJxUn5uJOrH8orSnQs= -github.com/openstack-k8s-operators/octavia-operator/api v0.5.1-0.20241115111947-2336829c2d73/go.mod h1:3bFE3g3OCC2vtwhxDKdjV7sezTj4yFeqP0C40Z5NOEA= +github.com/openstack-k8s-operators/octavia-operator/api v0.5.1-0.20241121093935-bc64ab6db016 h1:3e98HQ5eP3S5cdQ3/G4BpipgbtHiY6fDN+CYo2z3RqU= +github.com/openstack-k8s-operators/octavia-operator/api v0.5.1-0.20241121093935-bc64ab6db016/go.mod h1:3bFE3g3OCC2vtwhxDKdjV7sezTj4yFeqP0C40Z5NOEA= github.com/openstack-k8s-operators/openstack-baremetal-operator/api v0.5.1-0.20241118111717-a1d460a6d81f h1:2aM3rxATUmgPdghtm8MoN2WVACMI5XYSQFv1JZV8iqA= github.com/openstack-k8s-operators/openstack-baremetal-operator/api v0.5.1-0.20241118111717-a1d460a6d81f/go.mod h1:G9nampuSFs/9i2Ldx3OasU6oehWchwYuhBu1qMWktMg= -github.com/openstack-k8s-operators/ovn-operator/api v0.5.1-0.20241118072048-45d5df9ad730 h1:unZ61c7+dUAALmQHRAVuqqmaTU0Ga5QeU53a4VXwtQU= -github.com/openstack-k8s-operators/ovn-operator/api v0.5.1-0.20241118072048-45d5df9ad730/go.mod h1:q5nvyCqRoCM9y6s/n8GfrBUzsGJltCEy8C1usKtkeJA= +github.com/openstack-k8s-operators/ovn-operator/api v0.5.1-0.20241121095319-a34ad51b8446 h1:IPbI+S2an1puMVCKzyW6dBwsTJ9QmaK1Cj9/qFHrHMY= +github.com/openstack-k8s-operators/ovn-operator/api v0.5.1-0.20241121095319-a34ad51b8446/go.mod h1:q5nvyCqRoCM9y6s/n8GfrBUzsGJltCEy8C1usKtkeJA= github.com/openstack-k8s-operators/placement-operator/api v0.5.1-0.20241119131546-e4c1ba679d22 h1:/53HgWuy6ZeqDVHevrv8dINctLF5/NY94LG+lKtDP08= github.com/openstack-k8s-operators/placement-operator/api v0.5.1-0.20241119131546-e4c1ba679d22/go.mod h1:3XfvmllEbmTSFzX44Smpq5Ec5nzNAU+aiMgrYKwiXs4= github.com/openstack-k8s-operators/rabbitmq-cluster-operator/v2 v2.6.1-0.20241017142550-a3524acedd49 h1:/7SnnHfGCH/dwuZFNUx54zw4cnwv2w6hjONq16aoowM= github.com/openstack-k8s-operators/rabbitmq-cluster-operator/v2 v2.6.1-0.20241017142550-a3524acedd49/go.mod h1:6Mq2N/KtNFW20L+PQC5qkeK8R8UGadmGBXL8HDY6lcg= -github.com/openstack-k8s-operators/swift-operator/api v0.5.1-0.20241114094619-107d1aac9458 h1:jLM1a3sClYUKfWHdZzTZI9RIpJGA+H8XQh321CbO0D0= -github.com/openstack-k8s-operators/swift-operator/api v0.5.1-0.20241114094619-107d1aac9458/go.mod h1:JlOTO8hnn/RCDtmZXAvnpudqv38eEFGX6nbfwEbltv8= -github.com/openstack-k8s-operators/telemetry-operator/api v0.5.1-0.20241118203716-9550c8740911 h1:4OysgPT+NOnOtC7dAKc9xdHLnVdEMz6JYDwFd6w3fxI= -github.com/openstack-k8s-operators/telemetry-operator/api v0.5.1-0.20241118203716-9550c8740911/go.mod h1:wpC0oQUkW/a/BjgzZOEwknnKJxHY0DeAIqtAh7WNwSs= +github.com/openstack-k8s-operators/swift-operator/api v0.5.1-0.20241121093118-6ab57de4e6cc h1:ObbwXZbbXk+PQpYPZWmisdwzQaSHv9Lyk1juBLJctnM= +github.com/openstack-k8s-operators/swift-operator/api v0.5.1-0.20241121093118-6ab57de4e6cc/go.mod h1:JlOTO8hnn/RCDtmZXAvnpudqv38eEFGX6nbfwEbltv8= +github.com/openstack-k8s-operators/telemetry-operator/api v0.5.1-0.20241121100420-f2c8dd9aa6c3 h1:w4OXa9ozND2cI155qktb7OUiRjKiw1yMLf4BQm+qs7g= +github.com/openstack-k8s-operators/telemetry-operator/api v0.5.1-0.20241121100420-f2c8dd9aa6c3/go.mod h1:wpC0oQUkW/a/BjgzZOEwknnKJxHY0DeAIqtAh7WNwSs= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= diff --git a/config/crd/bases/core.openstack.org_openstackcontrolplanes.yaml b/config/crd/bases/core.openstack.org_openstackcontrolplanes.yaml index 2e422fae9..669280c40 100644 --- a/config/crd/bases/core.openstack.org_openstackcontrolplanes.yaml +++ b/config/crd/bases/core.openstack.org_openstackcontrolplanes.yaml @@ -10879,6 +10879,10 @@ spec: format: int32 minimum: 0 type: integer + nodeSelector: + additionalProperties: + type: string + type: object override: properties: service: @@ -14703,6 +14707,10 @@ spec: templates: additionalProperties: properties: + nodeSelector: + additionalProperties: + type: string + type: object replicas: default: 1 format: int32 @@ -14859,6 +14867,10 @@ spec: items: type: string type: array + nodeSelector: + additionalProperties: + type: string + type: object storageClass: default: "" type: string @@ -14881,6 +14893,10 @@ spec: items: type: string type: array + nodeSelector: + additionalProperties: + type: string + type: object override: properties: service: @@ -14986,6 +15002,10 @@ spec: format: int64 minimum: 1 type: integer + nodeSelector: + additionalProperties: + type: string + type: object partPower: default: 10 format: int64 @@ -15022,6 +15042,10 @@ spec: items: type: string type: array + nodeSelector: + additionalProperties: + type: string + type: object replicas: default: 1 format: int32 @@ -15462,6 +15486,10 @@ spec: items: type: string type: array + nodeSelector: + additionalProperties: + type: string + type: object override: properties: service: @@ -15556,7 +15584,6 @@ spec: type: object required: - databaseInstance - - memcachedInstance - secret type: object enabled: @@ -15614,6 +15641,10 @@ spec: items: type: string type: array + nodeSelector: + additionalProperties: + type: string + type: object passwordSelector: default: ceilometerService: CeilometerPassword @@ -16340,6 +16371,10 @@ spec: type: string type: object type: object + nodeSelector: + additionalProperties: + type: string + type: object type: object type: object tls: diff --git a/config/samples/nodeselectors/global/kustomization.yaml b/config/samples/nodeselectors/global/kustomization.yaml new file mode 100644 index 000000000..94aa1cafb --- /dev/null +++ b/config/samples/nodeselectors/global/kustomization.yaml @@ -0,0 +1,14 @@ +resources: +- ../../base/openstackcontrolplane + +patches: +- target: + kind: OpenStackControlPlane + name: .* + patch: |- + - op: replace + path: /metadata/name + value: openstack +- target: + kind: OpenStackControlPlane + path: patch.yaml diff --git a/config/samples/nodeselectors/global/patch.yaml b/config/samples/nodeselectors/global/patch.yaml new file mode 100644 index 000000000..5b9fde167 --- /dev/null +++ b/config/samples/nodeselectors/global/patch.yaml @@ -0,0 +1,7 @@ +apiVersion: core.openstack.org/v1beta1 +kind: OpenStackControlPlane +metadata: + name: openstack +spec: + nodeSelector: + node-role.kubernetes.io/worker: "" diff --git a/controllers/client/openstackclient_controller.go b/controllers/client/openstackclient_controller.go index db7ecdd15..d8d2eafc1 100644 --- a/controllers/client/openstackclient_controller.go +++ b/controllers/client/openstackclient_controller.go @@ -17,18 +17,15 @@ import ( "context" "errors" "fmt" - "reflect" "time" "github.com/go-logr/logr" - "golang.org/x/exp/slices" corev1 "k8s.io/api/core/v1" rbacv1 "k8s.io/api/rbac/v1" k8s_errors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" - "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/runtime" @@ -308,45 +305,16 @@ func (r *OpenStackClientReconciler) Reconcile(ctx context.Context, req ctrl.Requ }, } + spec := openstackclient.ClientPodSpec(ctx, instance, helper, configVarsHash) + op, err := controllerutil.CreateOrPatch(ctx, r.Client, osclient, func() error { isPodUpdate := !osclient.ObjectMeta.CreationTimestamp.IsZero() if !isPodUpdate { - osclient.Spec = openstackclient.ClientPodSpec(ctx, instance, helper, configVarsHash) + osclient.Spec = spec } else { - hashupdate := false - - f := func(e corev1.EnvVar) bool { - return e.Name == "CONFIG_HASH" - } - idx := slices.IndexFunc(osclient.Spec.Containers[0].Env, f) - - if idx >= 0 && osclient.Spec.Containers[0].Env[idx].Value != configVarsHash { - hashupdate = true - } - - switch { - case osclient.Spec.Containers[0].Image != instance.Spec.ContainerImage: - // if container image change force re-create by triggering NewForbidden - return k8s_errors.NewForbidden( - schema.GroupResource{Group: "", Resource: "pods"}, // Specify the group and resource type - osclient.Name, - errors.New("Cannot update Pod spec field - Spec.Containers[0].Image"), // Specify the error message - ) - case hashupdate: - // if config hash changed, recreate the pod to use new config - return k8s_errors.NewForbidden( - schema.GroupResource{Group: "", Resource: "pods"}, // Specify the group and resource type - osclient.Name, - errors.New("Config changed recreate pod"), // Specify the error message - ) - case !reflect.DeepEqual(osclient.Spec.NodeSelector, instance.Spec.NodeSelector): - // if NodeSelector change force re-create by triggering NewForbidden - return k8s_errors.NewForbidden( - schema.GroupResource{Group: "", Resource: "pods"}, // Specify the group and resource type - osclient.Name, - errors.New("Cannot update Pod spec field - Spec.NodeSelector"), // Specify the error message - ) - } + osclient.Spec.Containers[0].Env = spec.Containers[0].Env + osclient.Spec.NodeSelector = spec.NodeSelector + osclient.Spec.Containers[0].Image = instance.Spec.ContainerImage } osclient.Labels = util.MergeStringMaps(osclient.Labels, clientLabels) @@ -376,7 +344,7 @@ func (r *OpenStackClientReconciler) Reconcile(ctx context.Context, req ctrl.Requ } Log.Info(fmt.Sprintf("OpenStackClient pod deleted due to change %s", err.Error())) - return ctrl.Result{}, nil + return ctrl.Result{Requeue: true}, nil } return ctrl.Result{}, fmt.Errorf("Failed to create or update pod %s: %w", osclient.Name, err) diff --git a/go.mod b/go.mod index f76eeba6a..9c6d770b7 100644 --- a/go.mod +++ b/go.mod @@ -19,25 +19,25 @@ require ( github.com/openstack-k8s-operators/glance-operator/api v0.5.1-0.20241120062804-89e9fe93e886 github.com/openstack-k8s-operators/heat-operator/api v0.5.1-0.20241120140156-1c476cfe7c63 github.com/openstack-k8s-operators/horizon-operator/api v0.5.1-0.20241119161147-c38568cb3fb0 - github.com/openstack-k8s-operators/infra-operator/apis v0.5.1-0.20241118112815-d52a058b34a8 - github.com/openstack-k8s-operators/ironic-operator/api v0.5.1-0.20241114211630-5b4dcbed9b37 + github.com/openstack-k8s-operators/infra-operator/apis v0.5.1-0.20241120235143-b225194fd0fd + github.com/openstack-k8s-operators/ironic-operator/api v0.5.1-0.20241120225637-63d25e2bf291 github.com/openstack-k8s-operators/keystone-operator/api v0.5.1-0.20241119162247-18b741090348 github.com/openstack-k8s-operators/lib-common/modules/ansible v0.5.0 github.com/openstack-k8s-operators/lib-common/modules/certmanager v0.5.1-0.20241114091812-6dc9fd0961dc github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20241114091812-6dc9fd0961dc github.com/openstack-k8s-operators/lib-common/modules/storage v0.5.1-0.20241114091812-6dc9fd0961dc github.com/openstack-k8s-operators/lib-common/modules/test v0.5.1-0.20241114091812-6dc9fd0961dc - github.com/openstack-k8s-operators/manila-operator/api v0.5.1-0.20241117150431-21b7f58d9ddf + github.com/openstack-k8s-operators/manila-operator/api v0.5.1-0.20241121093406-bfd56f125086 github.com/openstack-k8s-operators/mariadb-operator/api v0.5.1-0.20241120160542-4b457715f74e - github.com/openstack-k8s-operators/neutron-operator/api v0.5.1-0.20241114104932-eae3f8cd032b + github.com/openstack-k8s-operators/neutron-operator/api v0.5.1-0.20241121095318-591a3bcbcda6 github.com/openstack-k8s-operators/nova-operator/api v0.5.1-0.20241119125634-42b7b8417b48 - github.com/openstack-k8s-operators/octavia-operator/api v0.5.1-0.20241115111947-2336829c2d73 + github.com/openstack-k8s-operators/octavia-operator/api v0.5.1-0.20241121093935-bc64ab6db016 github.com/openstack-k8s-operators/openstack-baremetal-operator/api v0.5.1-0.20241118111717-a1d460a6d81f github.com/openstack-k8s-operators/openstack-operator/apis v0.0.0-20240531084739-3b4c0451297c - github.com/openstack-k8s-operators/ovn-operator/api v0.5.1-0.20241118072048-45d5df9ad730 + github.com/openstack-k8s-operators/ovn-operator/api v0.5.1-0.20241121095319-a34ad51b8446 github.com/openstack-k8s-operators/placement-operator/api v0.5.1-0.20241119131546-e4c1ba679d22 - github.com/openstack-k8s-operators/swift-operator/api v0.5.1-0.20241114094619-107d1aac9458 - github.com/openstack-k8s-operators/telemetry-operator/api v0.5.1-0.20241118203716-9550c8740911 + github.com/openstack-k8s-operators/swift-operator/api v0.5.1-0.20241121093118-6ab57de4e6cc + github.com/openstack-k8s-operators/telemetry-operator/api v0.5.1-0.20241121100420-f2c8dd9aa6c3 github.com/openstack-k8s-operators/test-operator/api v0.5.1-0.20241118150825-cd41d06be047 github.com/rabbitmq/cluster-operator/v2 v2.11.0 go.uber.org/zap v1.27.0 diff --git a/go.sum b/go.sum index 6c0922920..ac806dec7 100644 --- a/go.sum +++ b/go.sum @@ -112,10 +112,10 @@ github.com/openstack-k8s-operators/heat-operator/api v0.5.1-0.20241120140156-1c4 github.com/openstack-k8s-operators/heat-operator/api v0.5.1-0.20241120140156-1c476cfe7c63/go.mod h1:PuXjq4bV3/mYo4OAD/4tTon0N7E9YYXZHWiZLeZFVek= github.com/openstack-k8s-operators/horizon-operator/api v0.5.1-0.20241119161147-c38568cb3fb0 h1:YtC+hqGKx9M8B6fHgA1eFlq1yjEiOWwp1zZqyFtjSbA= github.com/openstack-k8s-operators/horizon-operator/api v0.5.1-0.20241119161147-c38568cb3fb0/go.mod h1:ezxV+6xd12IRKespGaDlJCUQ301yxrBlQUCEbeYQgSA= -github.com/openstack-k8s-operators/infra-operator/apis v0.5.1-0.20241118112815-d52a058b34a8 h1:mmnunGX3tnIT4ErxFjYcKb38VLjnfe9JcIcU9LaW9rE= -github.com/openstack-k8s-operators/infra-operator/apis v0.5.1-0.20241118112815-d52a058b34a8/go.mod h1:6x5zgJJBjrOhsTtNALYrM2ecUH92kIoZbZ6w1fKHPfs= -github.com/openstack-k8s-operators/ironic-operator/api v0.5.1-0.20241114211630-5b4dcbed9b37 h1:k++YKQetyZqG6t+kWLhVUclgwLRKspCEyxeEWCeDgjM= -github.com/openstack-k8s-operators/ironic-operator/api v0.5.1-0.20241114211630-5b4dcbed9b37/go.mod h1:nKeZBXFCwbYxTpIW9mPs/SK+4cODkEZgs+yOytvafBo= +github.com/openstack-k8s-operators/infra-operator/apis v0.5.1-0.20241120235143-b225194fd0fd h1:6LmBamNQRwX76TiR+qo7Ejkb5bT2IPFhstkTWtVh7m4= +github.com/openstack-k8s-operators/infra-operator/apis v0.5.1-0.20241120235143-b225194fd0fd/go.mod h1:6x5zgJJBjrOhsTtNALYrM2ecUH92kIoZbZ6w1fKHPfs= +github.com/openstack-k8s-operators/ironic-operator/api v0.5.1-0.20241120225637-63d25e2bf291 h1:wK/7eRfMI4bJxqC4NFRdNJKPL9CPf5gSQHNsn2EfqIc= +github.com/openstack-k8s-operators/ironic-operator/api v0.5.1-0.20241120225637-63d25e2bf291/go.mod h1:nKeZBXFCwbYxTpIW9mPs/SK+4cODkEZgs+yOytvafBo= github.com/openstack-k8s-operators/keystone-operator/api v0.5.1-0.20241119162247-18b741090348 h1:mJeXL6JpNWe7d8wA8UZ1EI5T70f8HIgE2ecNjfPFIq4= github.com/openstack-k8s-operators/keystone-operator/api v0.5.1-0.20241119162247-18b741090348/go.mod h1:AZhHY6dZzGyG9iVOf1poD7pTS9c7ZG/f99Fg+GdFVEk= github.com/openstack-k8s-operators/lib-common/modules/ansible v0.5.0 h1:M6tou1UD+en6fcZtV64RPsDVdHH5up6oqtENDU8dRyE= @@ -130,28 +130,28 @@ github.com/openstack-k8s-operators/lib-common/modules/storage v0.5.1-0.202411140 github.com/openstack-k8s-operators/lib-common/modules/storage v0.5.1-0.20241114091812-6dc9fd0961dc/go.mod h1:tfgBeLRqmlH/NQkLPe7396rj+t0whv2wPuMb8Ttvh8w= github.com/openstack-k8s-operators/lib-common/modules/test v0.5.1-0.20241114091812-6dc9fd0961dc h1:knyjd0eg4DyY+dTDHSrE9QwrZ0mtr7MpASCrmhW+5pw= github.com/openstack-k8s-operators/lib-common/modules/test v0.5.1-0.20241114091812-6dc9fd0961dc/go.mod h1:LV0jo5etIsGyINpmB37i4oWR8zU6ApIuh7fsqGGA41o= -github.com/openstack-k8s-operators/manila-operator/api v0.5.1-0.20241117150431-21b7f58d9ddf h1:UsAefjZBqFl0dYMg/efe75ECm8cAwc/2FCEBPYjQfIY= -github.com/openstack-k8s-operators/manila-operator/api v0.5.1-0.20241117150431-21b7f58d9ddf/go.mod h1:0/qgnjufYIqe439/3aUU/cwnjDwdUlNR3jnRubLTD5o= +github.com/openstack-k8s-operators/manila-operator/api v0.5.1-0.20241121093406-bfd56f125086 h1:83nj2btbl2i06eJHtZdudyj0r1uuFqkorwkLdgssfp0= +github.com/openstack-k8s-operators/manila-operator/api v0.5.1-0.20241121093406-bfd56f125086/go.mod h1:0/qgnjufYIqe439/3aUU/cwnjDwdUlNR3jnRubLTD5o= github.com/openstack-k8s-operators/mariadb-operator/api v0.5.1-0.20241120160542-4b457715f74e h1:id6qqUWUMo0h7LoIhjQlMIjy4iihoBCi7Pe/jWjKHcY= github.com/openstack-k8s-operators/mariadb-operator/api v0.5.1-0.20241120160542-4b457715f74e/go.mod h1:348EPtAdpE2LxHAH4bHdCMNP7HyX6DevwEsF9DQ0S2k= -github.com/openstack-k8s-operators/neutron-operator/api v0.5.1-0.20241114104932-eae3f8cd032b h1:JMMPYDierS4YZdG9O/50kLihPQqmDz7p72btLy7Ibew= -github.com/openstack-k8s-operators/neutron-operator/api v0.5.1-0.20241114104932-eae3f8cd032b/go.mod h1:Kfuu3g4PSFpEowdWhbnTgSlDpsBGswQf/WU/kKQKK7s= +github.com/openstack-k8s-operators/neutron-operator/api v0.5.1-0.20241121095318-591a3bcbcda6 h1:ZFsA5wQwdITdXQxX99heejR9mWWsy8eGAaUoORk1pQI= +github.com/openstack-k8s-operators/neutron-operator/api v0.5.1-0.20241121095318-591a3bcbcda6/go.mod h1:Kfuu3g4PSFpEowdWhbnTgSlDpsBGswQf/WU/kKQKK7s= github.com/openstack-k8s-operators/nova-operator/api v0.5.1-0.20241119125634-42b7b8417b48 h1:eCvn/lCMqWTvlN74nFr7nG2EvZdvJPdSR9Ts2eTaM6c= github.com/openstack-k8s-operators/nova-operator/api v0.5.1-0.20241119125634-42b7b8417b48/go.mod h1:330SfEZuqG3b90HopY+Hk90y0OTyPcBa0GRKPUD7BHE= -github.com/openstack-k8s-operators/octavia-operator/api v0.5.1-0.20241115111947-2336829c2d73 h1:HWHbtCBbTv3zvluSpV4ZG8Ov0VJxUn5uJOrH8orSnQs= -github.com/openstack-k8s-operators/octavia-operator/api v0.5.1-0.20241115111947-2336829c2d73/go.mod h1:3bFE3g3OCC2vtwhxDKdjV7sezTj4yFeqP0C40Z5NOEA= +github.com/openstack-k8s-operators/octavia-operator/api v0.5.1-0.20241121093935-bc64ab6db016 h1:3e98HQ5eP3S5cdQ3/G4BpipgbtHiY6fDN+CYo2z3RqU= +github.com/openstack-k8s-operators/octavia-operator/api v0.5.1-0.20241121093935-bc64ab6db016/go.mod h1:3bFE3g3OCC2vtwhxDKdjV7sezTj4yFeqP0C40Z5NOEA= github.com/openstack-k8s-operators/openstack-baremetal-operator/api v0.5.1-0.20241118111717-a1d460a6d81f h1:2aM3rxATUmgPdghtm8MoN2WVACMI5XYSQFv1JZV8iqA= github.com/openstack-k8s-operators/openstack-baremetal-operator/api v0.5.1-0.20241118111717-a1d460a6d81f/go.mod h1:G9nampuSFs/9i2Ldx3OasU6oehWchwYuhBu1qMWktMg= -github.com/openstack-k8s-operators/ovn-operator/api v0.5.1-0.20241118072048-45d5df9ad730 h1:unZ61c7+dUAALmQHRAVuqqmaTU0Ga5QeU53a4VXwtQU= -github.com/openstack-k8s-operators/ovn-operator/api v0.5.1-0.20241118072048-45d5df9ad730/go.mod h1:q5nvyCqRoCM9y6s/n8GfrBUzsGJltCEy8C1usKtkeJA= +github.com/openstack-k8s-operators/ovn-operator/api v0.5.1-0.20241121095319-a34ad51b8446 h1:IPbI+S2an1puMVCKzyW6dBwsTJ9QmaK1Cj9/qFHrHMY= +github.com/openstack-k8s-operators/ovn-operator/api v0.5.1-0.20241121095319-a34ad51b8446/go.mod h1:q5nvyCqRoCM9y6s/n8GfrBUzsGJltCEy8C1usKtkeJA= github.com/openstack-k8s-operators/placement-operator/api v0.5.1-0.20241119131546-e4c1ba679d22 h1:/53HgWuy6ZeqDVHevrv8dINctLF5/NY94LG+lKtDP08= github.com/openstack-k8s-operators/placement-operator/api v0.5.1-0.20241119131546-e4c1ba679d22/go.mod h1:3XfvmllEbmTSFzX44Smpq5Ec5nzNAU+aiMgrYKwiXs4= github.com/openstack-k8s-operators/rabbitmq-cluster-operator/v2 v2.6.1-0.20241017142550-a3524acedd49 h1:/7SnnHfGCH/dwuZFNUx54zw4cnwv2w6hjONq16aoowM= github.com/openstack-k8s-operators/rabbitmq-cluster-operator/v2 v2.6.1-0.20241017142550-a3524acedd49/go.mod h1:6Mq2N/KtNFW20L+PQC5qkeK8R8UGadmGBXL8HDY6lcg= -github.com/openstack-k8s-operators/swift-operator/api v0.5.1-0.20241114094619-107d1aac9458 h1:jLM1a3sClYUKfWHdZzTZI9RIpJGA+H8XQh321CbO0D0= -github.com/openstack-k8s-operators/swift-operator/api v0.5.1-0.20241114094619-107d1aac9458/go.mod h1:JlOTO8hnn/RCDtmZXAvnpudqv38eEFGX6nbfwEbltv8= -github.com/openstack-k8s-operators/telemetry-operator/api v0.5.1-0.20241118203716-9550c8740911 h1:4OysgPT+NOnOtC7dAKc9xdHLnVdEMz6JYDwFd6w3fxI= -github.com/openstack-k8s-operators/telemetry-operator/api v0.5.1-0.20241118203716-9550c8740911/go.mod h1:wpC0oQUkW/a/BjgzZOEwknnKJxHY0DeAIqtAh7WNwSs= +github.com/openstack-k8s-operators/swift-operator/api v0.5.1-0.20241121093118-6ab57de4e6cc h1:ObbwXZbbXk+PQpYPZWmisdwzQaSHv9Lyk1juBLJctnM= +github.com/openstack-k8s-operators/swift-operator/api v0.5.1-0.20241121093118-6ab57de4e6cc/go.mod h1:JlOTO8hnn/RCDtmZXAvnpudqv38eEFGX6nbfwEbltv8= +github.com/openstack-k8s-operators/telemetry-operator/api v0.5.1-0.20241121100420-f2c8dd9aa6c3 h1:w4OXa9ozND2cI155qktb7OUiRjKiw1yMLf4BQm+qs7g= +github.com/openstack-k8s-operators/telemetry-operator/api v0.5.1-0.20241121100420-f2c8dd9aa6c3/go.mod h1:wpC0oQUkW/a/BjgzZOEwknnKJxHY0DeAIqtAh7WNwSs= github.com/openstack-k8s-operators/test-operator/api v0.5.1-0.20241118150825-cd41d06be047 h1:7fq7Zl2uFWHLWc4CLvEBEuIvKLO0JYDrqBZ1wtDfBQ8= github.com/openstack-k8s-operators/test-operator/api v0.5.1-0.20241118150825-cd41d06be047/go.mod h1:+fnm5nepo//2fdEFWsGCWzjOyshRbomLTWN2ylo1PQI= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= diff --git a/pkg/openstack/dnsmasq.go b/pkg/openstack/dnsmasq.go index cae7a8a06..7dc5e16d7 100644 --- a/pkg/openstack/dnsmasq.go +++ b/pkg/openstack/dnsmasq.go @@ -40,13 +40,14 @@ func ReconcileDNSMasqs(ctx context.Context, instance *corev1beta1.OpenStackContr instance.Spec.DNS.Template = &networkv1.DNSMasqSpec{} } + if instance.Spec.DNS.Template.NodeSelector == nil { + instance.Spec.DNS.Template.NodeSelector = &instance.Spec.NodeSelector + } + Log.Info("Reconciling DNSMasq", "DNSMasq.Namespace", instance.Namespace, "DNSMasq.Name", "dnsmasq") op, err := controllerutil.CreateOrPatch(ctx, helper.GetClient(), dnsmasq, func() error { instance.Spec.DNS.Template.DeepCopyInto(&dnsmasq.Spec) dnsmasq.Spec.ContainerImage = *version.Status.ContainerImages.InfraDnsmasqImage - if dnsmasq.Spec.NodeSelector == nil && instance.Spec.NodeSelector != nil { - dnsmasq.Spec.NodeSelector = instance.Spec.NodeSelector - } err := controllerutil.SetControllerReference(helper.GetBeforeObject(), dnsmasq, helper.GetScheme()) if err != nil { return err diff --git a/pkg/openstack/ironic.go b/pkg/openstack/ironic.go index 1c71e81c6..95c202615 100644 --- a/pkg/openstack/ironic.go +++ b/pkg/openstack/ironic.go @@ -47,6 +47,10 @@ func ReconcileIronic(ctx context.Context, instance *corev1beta1.OpenStackControl instance.Spec.Ironic.Template = &ironicv1.IronicSpecCore{} } + if instance.Spec.Ironic.Template.NodeSelector == nil { + instance.Spec.Ironic.Template.NodeSelector = &instance.Spec.NodeSelector + } + // add selector to service overrides for _, endpointType := range []service.Endpoint{service.EndpointPublic, service.EndpointInternal} { if instance.Spec.Ironic.Template.IronicAPI.Override.Service == nil { diff --git a/pkg/openstack/manila.go b/pkg/openstack/manila.go index 3f526429c..468ee64d0 100644 --- a/pkg/openstack/manila.go +++ b/pkg/openstack/manila.go @@ -106,11 +106,16 @@ func ReconcileManila(ctx context.Context, instance *corev1beta1.OpenStackControl instance.Spec.Manila.Template.ManilaAPI.TLS.API.Internal.SecretName = endpointDetails.GetEndptCertSecret(service.EndpointInternal) } + if instance.Spec.Manila.Template.NodeSelector == nil { + instance.Spec.Manila.Template.NodeSelector = &instance.Spec.NodeSelector + } + Log.Info("Reconciling Manila", "Manila.Namespace", instance.Namespace, "Manila.Name", "manila") op, err := controllerutil.CreateOrPatch(ctx, helper.GetClient(), manila, func() error { instance.Spec.Manila.Template.ManilaSpecBase.DeepCopyInto(&manila.Spec.ManilaSpecBase) instance.Spec.Manila.Template.ManilaAPI.DeepCopyInto(&manila.Spec.ManilaAPI.ManilaAPITemplateCore) instance.Spec.Manila.Template.ManilaScheduler.DeepCopyInto(&manila.Spec.ManilaScheduler.ManilaSchedulerTemplateCore) + manila.Spec.NodeSelector = instance.Spec.Manila.Template.NodeSelector manila.Spec.ManilaAPI.ContainerImage = *version.Status.ContainerImages.ManilaAPIImage manila.Spec.ManilaScheduler.ContainerImage = *version.Status.ContainerImages.ManilaSchedulerImage @@ -137,9 +142,6 @@ func ReconcileManila(ctx context.Context, instance *corev1beta1.OpenStackControl if manila.Spec.Secret == "" { manila.Spec.Secret = instance.Spec.Secret } - if manila.Spec.NodeSelector == nil && instance.Spec.NodeSelector != nil { - manila.Spec.NodeSelector = instance.Spec.NodeSelector - } if manila.Spec.DatabaseInstance == "" { //manila.Spec.DatabaseInstance = instance.Name // name of MariaDB we create here manila.Spec.DatabaseInstance = "openstack" //FIXME: see above diff --git a/pkg/openstack/memcached.go b/pkg/openstack/memcached.go index 92cf63b50..8bd701566 100644 --- a/pkg/openstack/memcached.go +++ b/pkg/openstack/memcached.go @@ -199,6 +199,10 @@ func reconcileMemcached( tlsCert = certSecret.Name } + if spec.NodeSelector == nil { + spec.NodeSelector = &instance.Spec.NodeSelector + } + op, err := controllerutil.CreateOrPatch(ctx, helper.GetClient(), memcached, func() error { spec.DeepCopyInto(&memcached.Spec.MemcachedSpecCore) diff --git a/pkg/openstack/neutron.go b/pkg/openstack/neutron.go index 211f3642f..425c7ac9a 100644 --- a/pkg/openstack/neutron.go +++ b/pkg/openstack/neutron.go @@ -141,6 +141,10 @@ func ReconcileNeutron(ctx context.Context, instance *corev1beta1.OpenStackContro instance.Spec.Neutron.Template.TLS.API.Internal.SecretName = endpointDetails.GetEndptCertSecret(service.EndpointInternal) } + if instance.Spec.Neutron.Template.NodeSelector == nil { + instance.Spec.Neutron.Template.NodeSelector = &instance.Spec.NodeSelector + } + Log.Info("Reconciling NeutronAPI", "NeutronAPI.Namespace", instance.Namespace, "NeutronAPI.Name", "neutron") op, err := controllerutil.CreateOrPatch(ctx, helper.GetClient(), neutronAPI, func() error { instance.Spec.Neutron.Template.DeepCopyInto(&neutronAPI.Spec.NeutronAPISpecCore) @@ -148,9 +152,6 @@ func ReconcileNeutron(ctx context.Context, instance *corev1beta1.OpenStackContro if neutronAPI.Spec.Secret == "" { neutronAPI.Spec.Secret = instance.Spec.Secret } - if neutronAPI.Spec.NodeSelector == nil && instance.Spec.NodeSelector != nil { - neutronAPI.Spec.NodeSelector = instance.Spec.NodeSelector - } if neutronAPI.Spec.DatabaseInstance == "" { neutronAPI.Spec.DatabaseInstance = "openstack" } diff --git a/pkg/openstack/octavia.go b/pkg/openstack/octavia.go index c3b2803c9..8a59cff54 100644 --- a/pkg/openstack/octavia.go +++ b/pkg/openstack/octavia.go @@ -64,6 +64,10 @@ func ReconcileOctavia(ctx context.Context, instance *corev1beta1.OpenStackContro instance.Spec.Octavia.Template = &octaviav1.OctaviaSpecCore{} } + if instance.Spec.Octavia.Template.NodeSelector == nil { + instance.Spec.Octavia.Template.NodeSelector = &instance.Spec.NodeSelector + } + // add selector to service overrides for _, endpointType := range []service.Endpoint{service.EndpointPublic, service.EndpointInternal} { if instance.Spec.Octavia.Template.OctaviaAPI.Override.Service == nil { diff --git a/pkg/openstack/openstackclient.go b/pkg/openstack/openstackclient.go index 4f49f0870..efc7fd520 100644 --- a/pkg/openstack/openstackclient.go +++ b/pkg/openstack/openstackclient.go @@ -47,6 +47,10 @@ func ReconcileOpenStackClient(ctx context.Context, instance *corev1.OpenStackCon return ctrl.Result{}, nil } + if instance.Spec.OpenStackClient.Template.NodeSelector == nil { + instance.Spec.OpenStackClient.Template.NodeSelector = &instance.Spec.NodeSelector + } + Log.Info("Reconciling OpenStackClient", "OpenStackClient.Namespace", instance.Namespace, "OpenStackClient.Name", openstackclient.Name) op, err := controllerutil.CreateOrPatch(ctx, helper.GetClient(), openstackclient, func() error { instance.Spec.OpenStackClient.Template.DeepCopyInto(&openstackclient.Spec.OpenStackClientSpecCore) diff --git a/pkg/openstack/ovn.go b/pkg/openstack/ovn.go index 25997af7a..32569abfc 100644 --- a/pkg/openstack/ovn.go +++ b/pkg/openstack/ovn.go @@ -142,6 +142,10 @@ func ReconcileOVNDbClusters(ctx context.Context, instance *corev1beta1.OpenStack dbcluster.TLS.SecretName = &certSecret.Name } + if dbcluster.NodeSelector == nil { + dbcluster.NodeSelector = &instance.Spec.NodeSelector + } + Log.Info("Reconciling OVNDBCluster", "OVNDBCluster.Namespace", instance.Namespace, "OVNDBCluster.Name", name) op, err := controllerutil.CreateOrPatch(ctx, helper.GetClient(), OVNDBCluster, func() error { @@ -154,9 +158,6 @@ func ReconcileOVNDbClusters(ctx context.Context, instance *corev1beta1.OpenStack OVNDBCluster.Spec.ContainerImage = *version.Status.ContainerImages.OvnSbDbclusterImage } - if OVNDBCluster.Spec.NodeSelector == nil && instance.Spec.NodeSelector != nil { - OVNDBCluster.Spec.NodeSelector = instance.Spec.NodeSelector - } if OVNDBCluster.Spec.StorageClass == "" { OVNDBCluster.Spec.StorageClass = instance.Spec.StorageClass } @@ -256,6 +257,10 @@ func ReconcileOVNNorthd(ctx context.Context, instance *corev1beta1.OpenStackCont } ovnNorthdSpec.TLS.CaBundleSecretName = instance.Status.TLS.CaBundleSecretName + if ovnNorthdSpec.NodeSelector == nil { + ovnNorthdSpec.NodeSelector = &instance.Spec.NodeSelector + } + Log.Info("Reconciling OVNNorthd", "OVNNorthd.Namespace", instance.Namespace, "OVNNorthd.Name", "ovnnorthd") op, err := controllerutil.CreateOrPatch(ctx, helper.GetClient(), OVNNorthd, func() error { @@ -263,10 +268,6 @@ func ReconcileOVNNorthd(ctx context.Context, instance *corev1beta1.OpenStackCont OVNNorthd.Spec.ContainerImage = *version.Status.ContainerImages.OvnNorthdImage - if OVNNorthd.Spec.NodeSelector == nil && instance.Spec.NodeSelector != nil { - OVNNorthd.Spec.NodeSelector = instance.Spec.NodeSelector - } - err := controllerutil.SetControllerReference(helper.GetBeforeObject(), OVNNorthd, helper.GetScheme()) if err != nil { return err @@ -373,6 +374,10 @@ func ReconcileOVNController(ctx context.Context, instance *corev1beta1.OpenStack } ovnControllerSpec.TLS.CaBundleSecretName = instance.Status.TLS.CaBundleSecretName + if ovnControllerSpec.NodeSelector == nil { + ovnControllerSpec.NodeSelector = &instance.Spec.NodeSelector + } + Log.Info("Reconciling OVNController", "OVNController.Namespace", instance.Namespace, "OVNController.Name", "ovncontroller") op, err := controllerutil.CreateOrPatch(ctx, helper.GetClient(), OVNController, func() error { @@ -381,10 +386,6 @@ func ReconcileOVNController(ctx context.Context, instance *corev1beta1.OpenStack OVNController.Spec.OvnContainerImage = *version.Status.ContainerImages.OvnControllerImage OVNController.Spec.OvsContainerImage = *version.Status.ContainerImages.OvnControllerOvsImage - if OVNController.Spec.NodeSelector == nil && instance.Spec.NodeSelector != nil { - OVNController.Spec.NodeSelector = instance.Spec.NodeSelector - } - err := controllerutil.SetControllerReference(helper.GetBeforeObject(), OVNController, helper.GetScheme()) if err != nil { return err diff --git a/pkg/openstack/rabbitmq.go b/pkg/openstack/rabbitmq.go index cbe7c21f9..c1f3ef979 100644 --- a/pkg/openstack/rabbitmq.go +++ b/pkg/openstack/rabbitmq.go @@ -310,6 +310,18 @@ func reconcileRabbitMQ( tlsCert = certSecret.Name } + if spec.Override.StatefulSet == nil { + spec.Override.StatefulSet = &defaultStatefulSet + } + + if spec.Override.StatefulSet.Spec.Template.Spec.NodeSelector == nil { + if spec.NodeSelector != nil { + spec.Override.StatefulSet.Spec.Template.Spec.NodeSelector = *spec.NodeSelector + } else { + spec.Override.StatefulSet.Spec.Template.Spec.NodeSelector = instance.Spec.NodeSelector + } + } + op, err := controllerutil.CreateOrPatch(ctx, helper.GetClient(), rabbitmq, func() error { rabbitmq.Spec.Image = *version.Status.ContainerImages.RabbitmqImage @@ -362,11 +374,6 @@ func reconcileRabbitMQ( rabbitmq.Spec.Persistence.StorageClassName = &instance.Spec.StorageClass } - if rabbitmq.Spec.Override.StatefulSet == nil { - Log.Info("Setting StatefulSet") - rabbitmq.Spec.Override.StatefulSet = &defaultStatefulSet - } - if rabbitmq.Spec.Override.Service != nil && rabbitmq.Spec.Override.Service.Spec != nil && rabbitmq.Spec.Override.Service.Spec.Type == corev1.ServiceTypeLoadBalancer { diff --git a/pkg/openstack/redis.go b/pkg/openstack/redis.go index 28b2881e7..33b161572 100644 --- a/pkg/openstack/redis.go +++ b/pkg/openstack/redis.go @@ -219,6 +219,10 @@ func reconcileRedis( tlsCert = certSecret.Name } + if spec.NodeSelector == nil { + spec.NodeSelector = &instance.Spec.NodeSelector + } + op, err := controllerutil.CreateOrPatch(ctx, helper.GetClient(), redis, func() error { spec.DeepCopyInto(&redis.Spec.RedisSpecCore) if tlsCert != "" { diff --git a/pkg/openstack/swift.go b/pkg/openstack/swift.go index afcc04c77..700e51315 100644 --- a/pkg/openstack/swift.go +++ b/pkg/openstack/swift.go @@ -46,6 +46,10 @@ func ReconcileSwift(ctx context.Context, instance *corev1beta1.OpenStackControlP instance.Spec.Swift.Template = &swiftv1.SwiftSpecCore{} } + if instance.Spec.Swift.Template.NodeSelector == nil { + instance.Spec.Swift.Template.NodeSelector = &instance.Spec.NodeSelector + } + // add selector to service overrides for _, endpointType := range []service.Endpoint{service.EndpointPublic, service.EndpointInternal} { if instance.Spec.Swift.Template.SwiftProxy.Override.Service == nil { diff --git a/pkg/openstack/telemetry.go b/pkg/openstack/telemetry.go index b9e08f9d7..9c72e91dc 100644 --- a/pkg/openstack/telemetry.go +++ b/pkg/openstack/telemetry.go @@ -58,6 +58,10 @@ func ReconcileTelemetry(ctx context.Context, instance *corev1beta1.OpenStackCont instance.Spec.Telemetry.Template = &telemetryv1.TelemetrySpecCore{} } + if instance.Spec.Telemetry.Template.NodeSelector == nil { + instance.Spec.Telemetry.Template.NodeSelector = &instance.Spec.NodeSelector + } + if err := helper.GetClient().Get(ctx, types.NamespacedName{Name: "telemetry", Namespace: instance.Namespace}, telemetry); err != nil { if !k8s_errors.IsNotFound(err) { return ctrl.Result{}, err diff --git a/pkg/openstackclient/funcs.go b/pkg/openstackclient/funcs.go index 661ce4302..c3975efea 100644 --- a/pkg/openstackclient/funcs.go +++ b/pkg/openstackclient/funcs.go @@ -87,8 +87,8 @@ func ClientPodSpec( }, } - if instance.Spec.NodeSelector != nil && len(instance.Spec.NodeSelector) > 0 { - podSpec.NodeSelector = instance.Spec.NodeSelector + if instance.Spec.NodeSelector != nil { + podSpec.NodeSelector = *instance.Spec.NodeSelector } return podSpec diff --git a/tests/functional/ctlplane/openstackoperator_controller_test.go b/tests/functional/ctlplane/openstackoperator_controller_test.go index d901b5e35..03e46dba3 100644 --- a/tests/functional/ctlplane/openstackoperator_controller_test.go +++ b/tests/functional/ctlplane/openstackoperator_controller_test.go @@ -1822,27 +1822,57 @@ var _ = Describe("OpenStackOperator controller", func() { th.DeleteInstance, CreateOpenStackControlPlane(names.OpenStackControlplaneName, spec), ) + + Eventually(func(g Gomega) { + keystoneAPI := keystone.GetKeystoneAPI(names.KeystoneAPIName) + g.Expect(keystoneAPI).Should(Not(BeNil())) + }, timeout, interval).Should(Succeed()) + keystone.SimulateKeystoneAPIReady(names.KeystoneAPIName) + + Eventually(func(g Gomega) { + osversion := GetOpenStackVersion(names.OpenStackControlplaneName) + g.Expect(osversion).Should(Not(BeNil())) + + th.ExpectCondition( + names.OpenStackVersionName, + ConditionGetterFunc(OpenStackVersionConditionGetter), + corev1.OpenStackVersionInitialized, + k8s_corev1.ConditionTrue, + ) + }, timeout, interval).Should(Succeed()) + + th.CreateSecret(types.NamespacedName{Name: "openstack-config-secret", Namespace: namespace}, map[string][]byte{"secure.yaml": []byte("foo")}) + th.CreateConfigMap(types.NamespacedName{Name: "openstack-config", Namespace: namespace}, map[string]interface{}{"clouds.yaml": string("foo"), "OS_CLOUD": "default"}) }) - It("should set the galera nodeSelector", func() { + It("sets nodeSelector in resource specs", func() { + Eventually(func(g Gomega) { + osc := th.GetPod(names.OpenStackClientName) + g.Expect(osc.Spec.NodeSelector).To(Equal(map[string]string{"foo": "bar"})) + }, timeout, interval).Should(Succeed()) Eventually(func(g Gomega) { db := mariadb.GetGalera(names.DBName) g.Expect(*db.Spec.NodeSelector).To(Equal(map[string]string{"foo": "bar"})) }, timeout, interval).Should(Succeed()) Eventually(func(g Gomega) { - db := mariadb.GetGalera(names.DBCell1Name) - g.Expect(*db.Spec.NodeSelector).To(Equal(map[string]string{"foo": "bar"})) + rmq := GetRabbitMQCluster(names.RabbitMQName) + g.Expect(rmq.Spec.Override.StatefulSet.Spec.Template.Spec.NodeSelector).To(Equal(map[string]string{"foo": "bar"})) }, timeout, interval).Should(Succeed()) + }) - It("should update the galera nodeSelector", func() { + It("updates nodeSelector in resource specs when changed", func() { + Eventually(func(g Gomega) { + osc := th.GetPod(names.OpenStackClientName) + g.Expect(osc.Spec.NodeSelector).To(Equal(map[string]string{"foo": "bar"})) + }, timeout, interval).Should(Succeed()) Eventually(func(g Gomega) { db := mariadb.GetGalera(names.DBName) g.Expect(*db.Spec.NodeSelector).To(Equal(map[string]string{"foo": "bar"})) }, timeout, interval).Should(Succeed()) Eventually(func(g Gomega) { - db := mariadb.GetGalera(names.DBCell1Name) - g.Expect(*db.Spec.NodeSelector).To(Equal(map[string]string{"foo": "bar"})) + rmq := GetRabbitMQCluster(names.RabbitMQName) + g.Expect(rmq.Spec.Override.StatefulSet.Spec.Template.Spec.NodeSelector).To(Equal(map[string]string{"foo": "bar"})) }, timeout, interval).Should(Succeed()) Eventually(func(g Gomega) { @@ -1854,55 +1884,126 @@ var _ = Describe("OpenStackOperator controller", func() { g.Expect(k8sClient.Update(ctx, OSCtlplane)).Should(Succeed()) }, timeout, interval).Should(Succeed()) + Eventually(func(g Gomega) { + osc := th.GetPod(names.OpenStackClientName) + g.Expect(osc.Spec.NodeSelector).To(Equal(map[string]string{"foo2": "bar2"})) + }, timeout, interval).Should(Succeed()) Eventually(func(g Gomega) { db := mariadb.GetGalera(names.DBName) g.Expect(*db.Spec.NodeSelector).To(Equal(map[string]string{"foo2": "bar2"})) }, timeout, interval).Should(Succeed()) Eventually(func(g Gomega) { - db := mariadb.GetGalera(names.DBCell1Name) - g.Expect(*db.Spec.NodeSelector).To(Equal(map[string]string{"foo2": "bar2"})) + rmq := GetRabbitMQCluster(names.RabbitMQName) + g.Expect(rmq.Spec.Override.StatefulSet.Spec.Template.Spec.NodeSelector).To(Equal(map[string]string{"foo2": "bar2"})) }, timeout, interval).Should(Succeed()) }) - It("should allow the galera nodeSelector to be overridden", func() { + It("allows nodeSelector service override", func() { + Eventually(func(g Gomega) { + osc := th.GetPod(names.OpenStackClientName) + g.Expect(osc.Spec.NodeSelector).To(Equal(map[string]string{"foo": "bar"})) + }, timeout, interval).Should(Succeed()) Eventually(func(g Gomega) { db := mariadb.GetGalera(names.DBName) g.Expect(*db.Spec.NodeSelector).To(Equal(map[string]string{"foo": "bar"})) }, timeout, interval).Should(Succeed()) Eventually(func(g Gomega) { - db := mariadb.GetGalera(names.DBCell1Name) - g.Expect(*db.Spec.NodeSelector).To(Equal(map[string]string{"foo": "bar"})) + rmq := GetRabbitMQCluster(names.RabbitMQName) + g.Expect(rmq.Spec.Override.StatefulSet.Spec.Template.Spec.NodeSelector).To(Equal(map[string]string{"foo": "bar"})) }, timeout, interval).Should(Succeed()) Eventually(func(g Gomega) { OSCtlplane := GetOpenStackControlPlane(names.OpenStackControlplaneName) - newNodeSelector := map[string]string{ - "foo2": "bar2", + oscNodeSelector := map[string]string{ + "foo": "osc", + } + OSCtlplane.Spec.OpenStackClient.Template.NodeSelector = &oscNodeSelector + + galeraNodeSelector := map[string]string{ + "foo": "galera", } galeraTemplates := *(OSCtlplane.Spec.Galera.Templates) dbTemplate := galeraTemplates[names.DBName.Name] - dbTemplate.NodeSelector = &newNodeSelector + dbTemplate.NodeSelector = &galeraNodeSelector galeraTemplates[names.DBName.Name] = dbTemplate + OSCtlplane.Spec.Galera.Templates = &galeraTemplates + + rmqNodeSelector := map[string]string{ + "foo": "rmq", + } + rmqTemplates := *OSCtlplane.Spec.Rabbitmq.Templates + rmqTemplate := rmqTemplates[names.RabbitMQName.Name] + rmqTemplate.NodeSelector = &rmqNodeSelector + rmqTemplates[names.RabbitMQName.Name] = rmqTemplate + OSCtlplane.Spec.Rabbitmq.Templates = &rmqTemplates - emptyNodeSelector := map[string]string{} - cell1Template := galeraTemplates[names.DBCell1Name.Name] - cell1Template.NodeSelector = &emptyNodeSelector - galeraTemplates[names.DBCell1Name.Name] = cell1Template + g.Expect(k8sClient.Update(ctx, OSCtlplane)).Should(Succeed()) + }, timeout, interval).Should(Succeed()) + + Eventually(func(g Gomega) { + osc := th.GetPod(names.OpenStackClientName) + g.Expect(osc.Spec.NodeSelector).To(Equal(map[string]string{"foo": "osc"})) + }, timeout, interval).Should(Succeed()) + Eventually(func(g Gomega) { + db := mariadb.GetGalera(names.DBName) + g.Expect(*db.Spec.NodeSelector).To(Equal(map[string]string{"foo": "galera"})) + }, timeout, interval).Should(Succeed()) + Eventually(func(g Gomega) { + rmq := GetRabbitMQCluster(names.RabbitMQName) + g.Expect(rmq.Spec.Override.StatefulSet.Spec.Template.Spec.NodeSelector).To(Equal(map[string]string{"foo": "rmq"})) + }, timeout, interval).Should(Succeed()) + }) + It("allows nodeSelector service override to empty", func() { + Eventually(func(g Gomega) { + osc := th.GetPod(names.OpenStackClientName) + g.Expect(osc.Spec.NodeSelector).To(Equal(map[string]string{"foo": "bar"})) + }, timeout, interval).Should(Succeed()) + Eventually(func(g Gomega) { + db := mariadb.GetGalera(names.DBName) + g.Expect(*db.Spec.NodeSelector).To(Equal(map[string]string{"foo": "bar"})) + }, timeout, interval).Should(Succeed()) + Eventually(func(g Gomega) { + rmq := GetRabbitMQCluster(names.RabbitMQName) + g.Expect(rmq.Spec.Override.StatefulSet.Spec.Template.Spec.NodeSelector).To(Equal(map[string]string{"foo": "bar"})) + }, timeout, interval).Should(Succeed()) + + Eventually(func(g Gomega) { + OSCtlplane := GetOpenStackControlPlane(names.OpenStackControlplaneName) + + oscNodeSelector := map[string]string{} + OSCtlplane.Spec.OpenStackClient.Template.NodeSelector = &oscNodeSelector + + galeraNodeSelector := map[string]string{} + galeraTemplates := *(OSCtlplane.Spec.Galera.Templates) + dbTemplate := galeraTemplates[names.DBName.Name] + dbTemplate.NodeSelector = &galeraNodeSelector + galeraTemplates[names.DBName.Name] = dbTemplate OSCtlplane.Spec.Galera.Templates = &galeraTemplates + rmqNodeSelector := map[string]string{} + rmqTemplates := *OSCtlplane.Spec.Rabbitmq.Templates + rmqTemplate := rmqTemplates[names.RabbitMQName.Name] + rmqTemplate.NodeSelector = &rmqNodeSelector + rmqTemplates[names.RabbitMQName.Name] = rmqTemplate + OSCtlplane.Spec.Rabbitmq.Templates = &rmqTemplates + g.Expect(k8sClient.Update(ctx, OSCtlplane)).Should(Succeed()) }, timeout, interval).Should(Succeed()) Eventually(func(g Gomega) { - db := mariadb.GetGalera(names.DBName) - g.Expect(*db.Spec.NodeSelector).To(Equal(map[string]string{"foo2": "bar2"})) + osc := th.GetPod(names.OpenStackClientName) + g.Expect(osc.Spec.NodeSelector).To(BeNil()) }, timeout, interval).Should(Succeed()) Eventually(func(g Gomega) { - db := mariadb.GetGalera(names.DBCell1Name) + db := mariadb.GetGalera(names.DBName) g.Expect(*db.Spec.NodeSelector).To(Equal(map[string]string{})) }, timeout, interval).Should(Succeed()) + Eventually(func(g Gomega) { + rmq := GetRabbitMQCluster(names.RabbitMQName) + g.Expect(rmq.Spec.Override.StatefulSet.Spec.Template.Spec.NodeSelector).To(BeNil()) + }, timeout, interval).Should(Succeed()) }) }) diff --git a/tests/kuttl/tests/ctlplane-nodeselectors/01-assert-deploy-openstack.yaml b/tests/kuttl/tests/ctlplane-nodeselectors/01-assert-deploy-openstack.yaml new file mode 120000 index 000000000..762a8cf31 --- /dev/null +++ b/tests/kuttl/tests/ctlplane-nodeselectors/01-assert-deploy-openstack.yaml @@ -0,0 +1 @@ +../../common/assert-sample-deployment.yaml \ No newline at end of file diff --git a/tests/kuttl/tests/ctlplane-nodeselectors/01-deploy-openstack.yaml b/tests/kuttl/tests/ctlplane-nodeselectors/01-deploy-openstack.yaml new file mode 100644 index 000000000..bfffa10c8 --- /dev/null +++ b/tests/kuttl/tests/ctlplane-nodeselectors/01-deploy-openstack.yaml @@ -0,0 +1,5 @@ +apiVersion: kuttl.dev/v1beta1 +kind: TestStep +commands: + - script: | + oc kustomize ../../../../config/samples/nodeselectors/global | oc apply -n $NAMESPACE -f - diff --git a/tests/kuttl/tests/ctlplane-nodeselectors/02-assert-nodeselector.yaml b/tests/kuttl/tests/ctlplane-nodeselectors/02-assert-nodeselector.yaml new file mode 100644 index 000000000..dfb3f117a --- /dev/null +++ b/tests/kuttl/tests/ctlplane-nodeselectors/02-assert-nodeselector.yaml @@ -0,0 +1,23 @@ +apiVersion: kuttl.dev/v1beta1 +kind: TestAssert +commands: + - script: | + echo "Checking all pods have expected nodeselector" + EXPECTED_NODE_SELECTOR="node-role.kubernetes.io/worker:" + BAD_OR_MISSING_NODE_SELECTOR=$(oc get pods -n $NAMESPACE -l service!=dnsmasq -o=go-template --template='{{ range .items }}{{ .metadata.name}}: {{ .spec.nodeSelector }}{{"\n"}}{{ end }}' | grep -v 'ovn-controller-.*-config' | sed -e '\!map\['"$EXPECTED_NODE_SELECTOR"'\]$!d') + BAD_OR_MISSING_NODE_SELECTOR_COUNT=$(echo -n "$BAD_OR_MISSING_NODE_SELECTOR" | wc -l) + if [ $BAD_OR_MISSING_NODE_SELECTOR_COUNT -ne 0 ]; then + echo "Found $BAD_OR_MISSING_NODE_SELECTOR_COUNT pods with bad or missing nodeselector:" + echo "$BAD_OR_MISSING_NODE_SELECTOR" + exit 1 + fi + - script: | + echo "Checking all cronjobs have expected nodeselector" + EXPECTED_NODE_SELECTOR="node-role.kubernetes.io/worker:" + BAD_OR_MISSING_NODE_SELECTOR=$(oc get cronjobs -n $NAMESPACE -o=go-template --template='{{ range .items }}{{ .metadata.name}}: {{ .spec.jobTemplate.spec.template.spec.nodeSelector }}{{"\n"}}{{ end }}' | grep -v 'ovn-controller-.*-config' | sed -e '\!map\['"$EXPECTED_NODE_SELECTOR"'\]$!d') + BAD_OR_MISSING_NODE_SELECTOR_COUNT=$(echo -n "$BAD_OR_MISSING_NODE_SELECTOR" | wc -l) + if [ $BAD_OR_MISSING_NODE_SELECTOR_COUNT -ne 0 ]; then + echo "Found $BAD_OR_MISSING_NODE_SELECTOR_COUNT cronjobs with bad or missing nodeselector:" + echo "$BAD_OR_MISSING_NODE_SELECTOR" + exit 1 + fi diff --git a/tests/kuttl/tests/ctlplane-nodeselectors/03-assert-deploy-openstack.yaml b/tests/kuttl/tests/ctlplane-nodeselectors/03-assert-deploy-openstack.yaml new file mode 120000 index 000000000..762a8cf31 --- /dev/null +++ b/tests/kuttl/tests/ctlplane-nodeselectors/03-assert-deploy-openstack.yaml @@ -0,0 +1 @@ +../../common/assert-sample-deployment.yaml \ No newline at end of file diff --git a/tests/kuttl/tests/ctlplane-nodeselectors/03-update-nodeselector.yaml b/tests/kuttl/tests/ctlplane-nodeselectors/03-update-nodeselector.yaml new file mode 100644 index 000000000..2d50bda2e --- /dev/null +++ b/tests/kuttl/tests/ctlplane-nodeselectors/03-update-nodeselector.yaml @@ -0,0 +1,16 @@ +apiVersion: kuttl.dev/v1beta1 +kind: TestStep +timeout: 60 +commands: + - script: | + oc patch dnsmasq -n $NAMESPACE dnsmasq --type='json' -p='[{ + "op": "replace", + "path": "/spec/nodeSelector", + "value": {"kubernetes.io/os":"linux"} + }]' + - script: | + oc patch openstackcontrolplane -n $NAMESPACE openstack --type='json' -p='[{ + "op": "replace", + "path": "/spec/nodeSelector", + "value": {"kubernetes.io/os":"linux"} + }]' diff --git a/tests/kuttl/tests/ctlplane-nodeselectors/04-assert-nodeselector.yaml b/tests/kuttl/tests/ctlplane-nodeselectors/04-assert-nodeselector.yaml new file mode 100644 index 000000000..031ccccc3 --- /dev/null +++ b/tests/kuttl/tests/ctlplane-nodeselectors/04-assert-nodeselector.yaml @@ -0,0 +1,23 @@ +apiVersion: kuttl.dev/v1beta1 +kind: TestAssert +commands: + - script: | + echo "Checking all running pods have new nodeselector" + EXPECTED_NODE_SELECTOR="kubernetes.io/os:linux" + BAD_OR_MISSING_NODE_SELECTOR=$(oc get pods -n $NAMESPACE -l service!=dnsmasq --field-selector=status.phase=Running -o=go-template --template='{{ range .items }}{{ .metadata.name}}: {{ .spec.nodeSelector }}{{"\n"}}{{ end }}' | grep -v 'ovn-controller-.*-config' | sed -e '\!map\['"$EXPECTED_NODE_SELECTOR"'\]$!d') + BAD_OR_MISSING_NODE_SELECTOR_COUNT=$(echo -n "$BAD_OR_MISSING_NODE_SELECTOR" | wc -l) + if [ $BAD_OR_MISSING_NODE_SELECTOR_COUNT -ne 0 ]; then + echo "Found $BAD_OR_MISSING_NODE_SELECTOR_COUNT pods with bad or missing nodeselector:" + echo "$BAD_OR_MISSING_NODE_SELECTOR" + exit 1 + fi + - script: | + echo "Checking all cronjobs have expected nodeselector" + EXPECTED_NODE_SELECTOR="kubernetes.io/os:linux" + BAD_OR_MISSING_NODE_SELECTOR=$(oc get cronjobs -n $NAMESPACE -o=go-template --template='{{ range .items }}{{ .metadata.name}}: {{ .spec.jobTemplate.spec.template.spec.nodeSelector }}{{"\n"}}{{ end }}' | grep -v 'ovn-controller-.*-config' | sed -e '\!map\['"$EXPECTED_NODE_SELECTOR"'\]$!d') + BAD_OR_MISSING_NODE_SELECTOR_COUNT=$(echo -n "$BAD_OR_MISSING_NODE_SELECTOR" | wc -l) + if [ $BAD_OR_MISSING_NODE_SELECTOR_COUNT -ne 0 ]; then + echo "Found $BAD_OR_MISSING_NODE_SELECTOR_COUNT cronjobs with bad or missing nodeselector:" + echo "$BAD_OR_MISSING_NODE_SELECTOR" + exit 1 + fi diff --git a/tests/kuttl/tests/ctlplane-nodeselectors/05-cleanup.yaml b/tests/kuttl/tests/ctlplane-nodeselectors/05-cleanup.yaml new file mode 100644 index 000000000..6b4992512 --- /dev/null +++ b/tests/kuttl/tests/ctlplane-nodeselectors/05-cleanup.yaml @@ -0,0 +1,13 @@ +apiVersion: kuttl.dev/v1beta1 +kind: TestStep +delete: +- apiVersion: core.openstack.org/v1beta1 + kind: OpenStackControlPlane + name: openstack +commands: +- script: | + oc delete --ignore-not-found=true -n $NAMESPACE pvc \ + srv-swift-storage-0 + oc delete secret --ignore-not-found=true combined-ca-bundle -n $NAMESPACE + oc delete secret -l service-cert -n $NAMESPACE + oc delete secret -l ca-cert -n $NAMESPACE diff --git a/tests/kuttl/tests/ctlplane-nodeselectors/05-errors-cleanup.yaml b/tests/kuttl/tests/ctlplane-nodeselectors/05-errors-cleanup.yaml new file mode 120000 index 000000000..4d7b8362e --- /dev/null +++ b/tests/kuttl/tests/ctlplane-nodeselectors/05-errors-cleanup.yaml @@ -0,0 +1 @@ +../../common/errors_cleanup_openstack.yaml \ No newline at end of file