Skip to content

Commit

Permalink
Expose lib-common AffinityOverrides for each GlanceAPI
Browse files Browse the repository at this point in the history
This patch updates the glance-operator GlanceAPITemplate to consume the
AffinityOverrides struct provided by lib-common.
It contains the minimum amount of parameters required to describe the
StatefulSet PodAffinity and PodAntiaffinity, and these overrides are processed
by the DistributePods function.

Signed-off-by: Francesco Pantano <[email protected]>
  • Loading branch information
fmount committed Nov 19, 2024
1 parent 6b8b8c3 commit 1bc7445
Show file tree
Hide file tree
Showing 11 changed files with 313 additions and 1,243 deletions.
360 changes: 57 additions & 303 deletions api/bases/glance.openstack.org_glanceapis.yaml

Large diffs are not rendered by default.

360 changes: 57 additions & 303 deletions api/bases/glance.openstack.org_glances.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion api/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@ require (
// must consistent within modules and service operators
replace github.com/openshift/api => github.com/openshift/api v0.0.0-20240830023148-b7d0481c9094 //allow-merging

replace github.com/openstack-k8s-operators/lib-common/modules/common => github.com/fmount/lib-common/modules/common v0.0.0-20241118144847-1e202d7aed52
replace github.com/openstack-k8s-operators/lib-common/modules/common => github.com/fmount/lib-common/modules/common v0.0.0-20241119142450-ac59d0a5898a
4 changes: 2 additions & 2 deletions api/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ github.com/evanphx/json-patch v5.7.0+incompatible h1:vgGkfT/9f8zE6tvSCe74nfpAVDQ
github.com/evanphx/json-patch v5.7.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/evanphx/json-patch/v5 v5.9.0 h1:kcBlZQbplgElYIlo/n1hJbls2z/1awpXxpRi0/FOJfg=
github.com/evanphx/json-patch/v5 v5.9.0/go.mod h1:VNkHZ/282BpEyt/tObQO8s5CMPmYYq14uClGH4abBuQ=
github.com/fmount/lib-common/modules/common v0.0.0-20241118144847-1e202d7aed52 h1:Hw64d5YJV4jB3OQ63Tzw6BWLNUY9B3DKXC2OYsAyrUA=
github.com/fmount/lib-common/modules/common v0.0.0-20241118144847-1e202d7aed52/go.mod h1:YpNTuJhDWhbXM50O3qBkhO7M+OOyRmWkNVmJ4y3cyFs=
github.com/fmount/lib-common/modules/common v0.0.0-20241119142450-ac59d0a5898a h1:W+C6UXACY8ur2ZFOcjkqkUei3yzuLCApqmKS8wkfSv8=
github.com/fmount/lib-common/modules/common v0.0.0-20241119142450-ac59d0a5898a/go.mod h1:YpNTuJhDWhbXM50O3qBkhO7M+OOyRmWkNVmJ4y3cyFs=
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
Expand Down
7 changes: 3 additions & 4 deletions api/v1beta1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,10 @@ type APIOverrideSpec struct {
// The key must be the endpoint type (public, internal)
Service map[service.Endpoint]service.RoutedOverrideSpec `json:"service,omitempty"`

// Template is the object that describes the pod that will be created if
// insufficient replicas are detected.
// More info: https://kubernetes.io/docs/concepts/workloads/controllers/replicationcontroller#pod-template
// APIAffinity exposes PodAffinity and PodAntiaffinity overrides that are applied
// to the StatefulSet
// +optional
APIAffinity affinity.AffinityOverrideSpec `json:"affinity,omitempty"`
APIAffinity affinity.Overrides `json:"scheduling,omitempty"`
}

// SetupDefaults - initializes any CRD field defaults based on environment variables (the defaulting mechanism itself is implemented via webhooks)
Expand Down
360 changes: 57 additions & 303 deletions config/crd/bases/glance.openstack.org_glanceapis.yaml

Large diffs are not rendered by default.

360 changes: 57 additions & 303 deletions config/crd/bases/glance.openstack.org_glances.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,4 @@ replace github.com/openstack-k8s-operators/glance-operator/api => ./api
// must consistent within modules and service operators
replace github.com/openshift/api => github.com/openshift/api v0.0.0-20240830023148-b7d0481c9094 //allow-merging

replace github.com/openstack-k8s-operators/lib-common/modules/common => github.com/fmount/lib-common/modules/common v0.0.0-20241118144847-1e202d7aed52
replace github.com/openstack-k8s-operators/lib-common/modules/common => github.com/fmount/lib-common/modules/common v0.0.0-20241119142450-ac59d0a5898a
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ github.com/evanphx/json-patch v5.7.0+incompatible h1:vgGkfT/9f8zE6tvSCe74nfpAVDQ
github.com/evanphx/json-patch v5.7.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/evanphx/json-patch/v5 v5.9.0 h1:kcBlZQbplgElYIlo/n1hJbls2z/1awpXxpRi0/FOJfg=
github.com/evanphx/json-patch/v5 v5.9.0/go.mod h1:VNkHZ/282BpEyt/tObQO8s5CMPmYYq14uClGH4abBuQ=
github.com/fmount/lib-common/modules/common v0.0.0-20241118144847-1e202d7aed52 h1:Hw64d5YJV4jB3OQ63Tzw6BWLNUY9B3DKXC2OYsAyrUA=
github.com/fmount/lib-common/modules/common v0.0.0-20241118144847-1e202d7aed52/go.mod h1:YpNTuJhDWhbXM50O3qBkhO7M+OOyRmWkNVmJ4y3cyFs=
github.com/fmount/lib-common/modules/common v0.0.0-20241119142450-ac59d0a5898a h1:W+C6UXACY8ur2ZFOcjkqkUei3yzuLCApqmKS8wkfSv8=
github.com/fmount/lib-common/modules/common v0.0.0-20241119142450-ac59d0a5898a/go.mod h1:YpNTuJhDWhbXM50O3qBkhO7M+OOyRmWkNVmJ4y3cyFs=
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
Expand Down
2 changes: 1 addition & 1 deletion pkg/glanceapi/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func StatefulSet(
labels map[string]string,
annotations map[string]string,
privileged bool,
affinityOverride *affinity.AffinityOverrideSpec,
affinityOverride *affinity.Overrides,
) (*appsv1.StatefulSet, error) {
userID := glance.GlanceUID
startupProbe := &corev1.Probe{
Expand Down
95 changes: 75 additions & 20 deletions test/functional/glance_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
glancev1 "github.com/openstack-k8s-operators/glance-operator/api/v1beta1"
"github.com/openstack-k8s-operators/glance-operator/pkg/glance"
memcachedv1 "github.com/openstack-k8s-operators/infra-operator/apis/memcached/v1beta1"
"github.com/openstack-k8s-operators/lib-common/modules/common/affinity"
"github.com/openstack-k8s-operators/lib-common/modules/common/condition"
util "github.com/openstack-k8s-operators/lib-common/modules/common/util"
mariadb_test "github.com/openstack-k8s-operators/mariadb-operator/api/test/helpers"
Expand Down Expand Up @@ -444,25 +445,24 @@ var _ = Describe("Glance controller", func() {
infra.SimulateMemcachedReady(glanceTest.GlanceMemcached)

affinityOverride := map[string]interface{}{
"podAntiAffinity": map[string]interface{}{
"preferredDuringSchedulingIgnoredDuringExecution": []map[string]interface{}{
{
"podAffinityTerm": map[string]interface{}{
"labelSelector": map[string]interface{}{
"matchExpressions": []interface{}{
map[string]interface{}{
"key": "app",
"operator": "In",
"values": []string{
glanceTest.GlanceService.Name,
},
},
},
},
"topologyKey": "kubernetes.io/hostname",
},
"weight": 70,
"antiAffinity": map[string]interface{}{
"preferred": map[string]interface{}{
"weight": 100,
"selectorKey": "glance",
"selectorValues": []string{
glanceTest.Instance.Name,
},
"topologyKey": corev1.LabelHostname,
},
},
"affinity": map[string]interface{}{
"preferred": map[string]interface{}{
"weight": 100,
"selectorKey": "foo",
"selectorValues": []string{
glanceTest.Instance.Name,
},
"topologyKey": corev1.LabelTopologyZone,
},
},
}
Expand All @@ -471,7 +471,6 @@ var _ = Describe("Glance controller", func() {
"storage": map[string]interface{}{
"storageRequest": glanceTest.GlancePVCSize,
},
"storageRequest": glanceTest.GlancePVCSize,
"secret": SecretName,
"databaseInstance": "openstack",
"databaseAccount": glanceTest.GlanceDatabaseAccount.Name,
Expand All @@ -482,7 +481,7 @@ var _ = Describe("Glance controller", func() {
"containerImage": glancev1.GlanceAPIContainerImage,
"networkAttachments": []string{"internalapi"},
"override": map[string]interface{}{
"affinity": affinityOverride,
"scheduling": affinityOverride,
},
},
},
Expand Down Expand Up @@ -525,6 +524,62 @@ var _ = Describe("Glance controller", func() {
})
})

When("Glance CR instance is built with an empty Affinity override", func() {
BeforeEach(func() {
DeferCleanup(infra.DeleteMemcached, infra.CreateMemcached(namespace, glanceTest.MemcachedInstance, memcachedSpec))
infra.SimulateMemcachedReady(glanceTest.GlanceMemcached)

rawSpec := map[string]interface{}{
"storage": map[string]interface{}{
"storageRequest": glanceTest.GlancePVCSize,
},
"secret": SecretName,
"databaseInstance": "openstack",
"databaseAccount": glanceTest.GlanceDatabaseAccount.Name,
"keystoneEndpoint": "default",
"customServiceConfig": GlanceDummyBackend,
"glanceAPIs": map[string]interface{}{
"default": map[string]interface{}{
"containerImage": glancev1.GlanceAPIContainerImage,
"networkAttachments": []string{"internalapi"},
},
},
}

DeferCleanup(th.DeleteInstance, CreateGlance(glanceTest.Instance, rawSpec))
DeferCleanup(
mariadb.DeleteDBService,
mariadb.CreateDBService(
glanceTest.Instance.Namespace,
GetGlance(glanceName).Spec.DatabaseInstance,
corev1.ServiceSpec{
Ports: []corev1.ServicePort{{Port: 3306}},
},
),
)
mariadb.SimulateMariaDBDatabaseCompleted(glanceTest.GlanceDatabaseName)
mariadb.SimulateMariaDBAccountCompleted(glanceTest.GlanceDatabaseAccount)
th.SimulateJobSuccess(glanceTest.GlanceDBSync)
keystoneAPI := keystone.CreateKeystoneAPI(glanceTest.Instance.Namespace)
DeferCleanup(keystone.DeleteKeystoneAPI, keystoneAPI)
keystone.SimulateKeystoneServiceReady(glanceTest.KeystoneService)
})

It("Check the resulting GlanceAPI have the right affinity set generated sub-CRs", func() {
th.SimulateStatefulSetReplicaReady(glanceTest.GlanceInternalStatefulSet)
th.SimulateStatefulSetReplicaReady(glanceTest.GlanceExternalStatefulSet)

// Retrieve the generated resources and the two internal/external
// instances that are split behind the scenes
internalAPI := GetGlanceAPI(glanceTest.GlanceInternal)
externalAPI := GetGlanceAPI(glanceTest.GlanceExternal)

// Verify the affinity is not set
Expect(internalAPI.Spec.Override.APIAffinity).To(Equal(affinity.Overrides{Affinity: nil, AntiAffinity: nil}))
Expect(externalAPI.Spec.Override.APIAffinity).To(Equal(affinity.Overrides{Affinity: nil, AntiAffinity: nil}))
})
})

// Run MariaDBAccount suite tests. these are pre-packaged ginkgo tests
// that exercise standard account create / update patterns that should be
// common to all controllers that ensure MariaDBAccount CRs.
Expand Down

0 comments on commit 1bc7445

Please sign in to comment.