Skip to content

Commit

Permalink
Update glanceAPI controller to consume topology functions from lib-co…
Browse files Browse the repository at this point in the history
…mmon

This patch updates the glance-operator to consume a TopologyRef struct
and the related functions from lib-common [1]. This allows to avoid
code duplication while spreading the pattern across the board.

[1] openstack-k8s-operators/lib-common#594

Signed-off-by: Francesco Pantano <[email protected]>
  • Loading branch information
fmount committed Jan 29, 2025
1 parent 105e69c commit afcc9f9
Show file tree
Hide file tree
Showing 12 changed files with 165 additions and 212 deletions.
14 changes: 7 additions & 7 deletions api/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ go 1.21

require (
github.com/google/go-cmp v0.6.0
github.com/openstack-k8s-operators/infra-operator/apis v0.5.1-0.20250120135015-2a1b8e167212
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250120114122-4bcef17ff6fa
github.com/openstack-k8s-operators/infra-operator/apis v0.5.1-0.20250123115751-98853871de94
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250128130522-53b65fcdadca
github.com/openstack-k8s-operators/lib-common/modules/storage v0.5.1-0.20241216113837-d172b3ac0f4e
k8s.io/api v0.29.12
k8s.io/apimachinery v0.29.12
k8s.io/api v0.29.13
k8s.io/apimachinery v0.29.13
sigs.k8s.io/controller-runtime v0.17.6
)

Expand Down Expand Up @@ -56,9 +56,9 @@ require (
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.29.12 // indirect
k8s.io/client-go v0.29.12 // indirect
k8s.io/component-base v0.29.12 // indirect
k8s.io/apiextensions-apiserver v0.29.13 // indirect
k8s.io/client-go v0.29.13 // indirect
k8s.io/component-base v0.29.13 // indirect
k8s.io/klog/v2 v2.120.1 // indirect
k8s.io/kube-openapi v0.0.0-20240322212309-b815d8309940 // indirect
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect
Expand Down
28 changes: 14 additions & 14 deletions api/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ github.com/onsi/gomega v1.34.1 h1:EUMJIKUjM8sKjYbtxQI9A4z2o+rruxnzNvpknOXie6k=
github.com/onsi/gomega v1.34.1/go.mod h1:kU1QgUvBDLXBJq618Xvm2LUX6rSAfRaFRTcdOeDLwwY=
github.com/openshift/api v0.0.0-20240830023148-b7d0481c9094 h1:J1wuGhVxpsHykZBa6Beb1gQ96Ptej9AE/BvwCBiRj1E=
github.com/openshift/api v0.0.0-20240830023148-b7d0481c9094/go.mod h1:CxgbWAlvu2iQB0UmKTtRu1YfepRg1/vJ64n2DlIEVz4=
github.com/openstack-k8s-operators/infra-operator/apis v0.5.1-0.20250120135015-2a1b8e167212 h1:6CSlrFvo9sDtJowI/hB9ZYdqhZdmpz2Gzz4EaqtlNpM=
github.com/openstack-k8s-operators/infra-operator/apis v0.5.1-0.20250120135015-2a1b8e167212/go.mod h1:TDaE7BVQvJwJGFm33R6xcPTeF8LKAnMh+a1ho+YqJHs=
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250120114122-4bcef17ff6fa h1:gzvO0w21wkyeex1UaD+AaYEuqEId/oYnARaxE4kATNc=
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250120114122-4bcef17ff6fa/go.mod h1:YpNTuJhDWhbXM50O3qBkhO7M+OOyRmWkNVmJ4y3cyFs=
github.com/openstack-k8s-operators/infra-operator/apis v0.5.1-0.20250123115751-98853871de94 h1:qOSjHqncEAJeBBCITKqq3shZMuGbDC+YBiRnGIoMnoI=
github.com/openstack-k8s-operators/infra-operator/apis v0.5.1-0.20250123115751-98853871de94/go.mod h1:TDaE7BVQvJwJGFm33R6xcPTeF8LKAnMh+a1ho+YqJHs=
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250128130522-53b65fcdadca h1:VzIM4LLWAJX9eDC2XvwLvaFNP7BnekNTQ9HUb6C/jbw=
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250128130522-53b65fcdadca/go.mod h1:KxnNSUk15llkKTSq/bQEE7pnc0IMk44fxhoBRpimMa8=
github.com/openstack-k8s-operators/lib-common/modules/storage v0.5.1-0.20241216113837-d172b3ac0f4e h1:Qz0JFEoRDUyjEWorNY3LggwxTsmpMtQkcpmZDQulGHQ=
github.com/openstack-k8s-operators/lib-common/modules/storage v0.5.1-0.20241216113837-d172b3ac0f4e/go.mod h1:tfgBeLRqmlH/NQkLPe7396rj+t0whv2wPuMb8Ttvh8w=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
Expand Down Expand Up @@ -183,16 +183,16 @@ gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
k8s.io/api v0.29.12 h1:SsEEMtFupOAt3pAAtAz0PDu+54g3L5rwbSCi0xQzAJM=
k8s.io/api v0.29.12/go.mod h1:QFwqOP+7LNoAG1RI3vKAFxjKSLQTCamcPzAQ0Z/Yhuk=
k8s.io/apiextensions-apiserver v0.29.12 h1:xoQfYPwAzfcoH/MVuQiSPTWmFrmblvYbUMODpfYyyw8=
k8s.io/apiextensions-apiserver v0.29.12/go.mod h1:L1GHiWK2bkYrZOkFtChfkVpPUh9Ogr6gmShM28Yhqk0=
k8s.io/apimachinery v0.29.12 h1:k6OdfK9xaNANQvWkl1pSICJGLjB4jSuJ3gGP9hBKOhE=
k8s.io/apimachinery v0.29.12/go.mod h1:i3FJVwhvSp/6n8Fl4K97PJEP8C+MM+aoDq4+ZJBf70Y=
k8s.io/client-go v0.29.12 h1:PjwJXavmpAqOWBRy4U5V/g3JQBpclIHEn5dvfTfsY+w=
k8s.io/client-go v0.29.12/go.mod h1:hRHG6tAKxaLVKF5SlMqgXrbqPEoUcUpJGFFrC3jU69A=
k8s.io/component-base v0.29.12 h1:NuFNzBSF3Iopih6VpvYmtjpdN1MLc9PcByl60fcJ0tQ=
k8s.io/component-base v0.29.12/go.mod h1:YHua3E5Lvnva6dXqGqiuRj8CxhBw7g6KgYV/dcS7LBU=
k8s.io/api v0.29.13 h1:VkMIbjJw1t2VgTatg8ggzI93LOfFa8z8SzAYzXtWuEg=
k8s.io/api v0.29.13/go.mod h1:fBWhXqqE25b46PZEVA2DXN2EuhNg1ZT3VRyb5JitLG8=
k8s.io/apiextensions-apiserver v0.29.13 h1:3xsTohNwndx4NJjgqoi5VuBPWeG4yY4VXOF62ugXvhU=
k8s.io/apiextensions-apiserver v0.29.13/go.mod h1:plxNh3qMNsiMo4svQtkVp47n+2/rwm/c8FTJYR6rikQ=
k8s.io/apimachinery v0.29.13 h1:a7I4uQtlfaL+UTRGFhl8lLd2nHBR7qt+axhQLtpLYMg=
k8s.io/apimachinery v0.29.13/go.mod h1:i3FJVwhvSp/6n8Fl4K97PJEP8C+MM+aoDq4+ZJBf70Y=
k8s.io/client-go v0.29.13 h1:M2scR9NWGlzI2YoIxTgwx2N3OA+dXqN87zsM4tvewmA=
k8s.io/client-go v0.29.13/go.mod h1:BBzF0Pr78Y8DM20j22E6tOMwTBpFaKnSnn6N0pNe4VE=
k8s.io/component-base v0.29.13 h1:RbksXVzXYYYvmOCArMKIkxna5eTt6DjI4Zy/4H3JFLo=
k8s.io/component-base v0.29.13/go.mod h1:pjMLwLNxDg0JvXRc69GIFUEawiZEtDzm0yAJ5+Naj9s=
k8s.io/klog/v2 v2.120.1 h1:QXU6cPEOIslTGvZaXvFWiP9VKyeet3sawzTOvdXb4Vw=
k8s.io/klog/v2 v2.120.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
k8s.io/kube-openapi v0.0.0-20240322212309-b815d8309940 h1:qVoMaQV5t62UUvHe16Q3eb2c5HPzLHYzsi0Tu/xLndo=
Expand Down
22 changes: 4 additions & 18 deletions api/v1beta1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/openstack-k8s-operators/lib-common/modules/common/service"
"github.com/openstack-k8s-operators/lib-common/modules/common/tls"
"github.com/openstack-k8s-operators/lib-common/modules/common/util"
"github.com/openstack-k8s-operators/lib-common/modules/common/topology"
corev1 "k8s.io/api/core/v1"
)

Expand Down Expand Up @@ -61,9 +62,9 @@ type GlanceAPITemplate struct {
NodeSelector *map[string]string `json:"nodeSelector,omitempty"`

// +kubebuilder:validation:Optional
// Topology to apply the Policy defined by the associated CR referenced by
// name
Topology *TopologyRef `json:"topologyRef,omitempty"`
// TopologyRef to apply the Topology defined by the associated CR referenced
// by name
TopologyRef *topology.TopoRef `json:"topologyRef,omitempty"`

// +kubebuilder:validation:Optional
// CustomServiceConfig - customize the service config using this parameter to change service defaults,
Expand Down Expand Up @@ -113,21 +114,6 @@ type GlanceAPITemplate struct {
APITimeout int `json:"apiTimeout,omitempty"`
}

// TopologyRef -
type TopologyRef struct {
// +kubebuilder:validation:Optional
// Name - The Topology CR name that Glance references
Name string `json:"name"`

// +kubebuilder:validation:Optional
// Namespace - The Namespace to fetch the Topology CR referenced
// NOTE: Namespace currently points by default to the same namespace where
// Glance is deployed. Customizing the namespace is not supported and
// webhooks prevent editing this field to a value different from the
// current project
Namespace string `json:"namespace,omitempty"`
}

// Storage -
type Storage struct {
// +kubebuilder:validation:Optional
Expand Down
7 changes: 4 additions & 3 deletions api/v1beta1/glance_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package v1beta1
import (
condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
"github.com/openstack-k8s-operators/lib-common/modules/storage"
"github.com/openstack-k8s-operators/lib-common/modules/common/topology"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -73,9 +74,9 @@ type GlanceSpecCore struct {
NodeSelector *map[string]string `json:"nodeSelector,omitempty"`

// +kubebuilder:validation:Optional
// Topology to apply the Policy defined by the associated CR referenced by
// name
Topology *TopologyRef `json:"topologyRef,omitempty"`
// TopologyRef to apply the Topology defined by the associated CR referenced
// by name
TopologyRef *topology.TopoRef `json:"topologyRef,omitempty"`

// +kubebuilder:validation:Optional
// +kubebuilder:default=false
Expand Down
20 changes: 10 additions & 10 deletions api/v1beta1/glance_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,16 +219,16 @@ func (r *Glance) ValidateCreate() (admission.Warnings, error) {
var allErrs field.ErrorList
basePath := field.NewPath("spec")

// When a Topology CR is referenced, fail if a different Namespace is
// When a TopologyRef CR is referenced, fail if a different Namespace is
// referenced because is not supported
if r.Spec.Topology != nil {
if err := topologyv1.ValidateTopologyNamespace(r.Spec.Topology.Namespace, *basePath, r.Namespace); err != nil {
if r.Spec.TopologyRef != nil {
if err := topologyv1.ValidateTopologyNamespace(r.Spec.TopologyRef.Namespace, *basePath, r.Namespace); err != nil {
allErrs = append(allErrs, err)
}
}
for key, glanceAPI := range r.Spec.GlanceAPIs {
if glanceAPI.Topology != nil {
if err := topologyv1.ValidateTopologyNamespace(glanceAPI.Topology.Namespace, *basePath.Child("glanceAPIs"), r.Namespace); err != nil {
if glanceAPI.TopologyRef != nil {
if err := topologyv1.ValidateTopologyNamespace(glanceAPI.TopologyRef.Namespace, *basePath.Child("glanceAPIs"), r.Namespace); err != nil {
allErrs = append(allErrs, err)
}
}
Expand Down Expand Up @@ -320,16 +320,16 @@ func (r *Glance) ValidateUpdate(old runtime.Object) (admission.Warnings, error)
var allErrs field.ErrorList
basePath := field.NewPath("spec")

// When a Topology CR is referenced, fail if a different Namespace is
// When a TopologyRef CR is referenced, fail if a different Namespace is
// referenced because is not supported
if r.Spec.Topology != nil {
if err := topologyv1.ValidateTopologyNamespace(r.Spec.Topology.Namespace, *basePath, r.Namespace); err != nil {
if r.Spec.TopologyRef != nil {
if err := topologyv1.ValidateTopologyNamespace(r.Spec.TopologyRef.Namespace, *basePath, r.Namespace); err != nil {
allErrs = append(allErrs, err)
}
}
for key, glanceAPI := range r.Spec.GlanceAPIs {
if glanceAPI.Topology != nil {
if err := topologyv1.ValidateTopologyNamespace(glanceAPI.Topology.Namespace, *basePath.Child("glanceAPIs"), r.Namespace); err != nil {
if glanceAPI.TopologyRef != nil {
if err := topologyv1.ValidateTopologyNamespace(glanceAPI.TopologyRef.Namespace, *basePath.Child("glanceAPIs"), r.Namespace); err != nil {
allErrs = append(allErrs, err)
}
}
Expand Down
28 changes: 7 additions & 21 deletions api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,5 @@ rules:
verbs:
- get
- list
- patch
- update
- watch
4 changes: 2 additions & 2 deletions controllers/glance_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -869,8 +869,8 @@ func (r *GlanceReconciler) apiDeploymentCreateOrUpdate(

// If topology is not present in the underlying GlanceAPI,
// inherit from the top-level CR
if apiSpec.GlanceAPITemplate.Topology == nil {
apiSpec.GlanceAPITemplate.Topology = instance.Spec.Topology
if apiSpec.GlanceAPITemplate.TopologyRef == nil {
apiSpec.GlanceAPITemplate.TopologyRef = instance.Spec.TopologyRef
}

// Add the API name to the GlanceAPI instance as a label
Expand Down
Loading

0 comments on commit afcc9f9

Please sign in to comment.