Skip to content

Commit

Permalink
Simplify the Storage interface for GlanceAPI
Browse files Browse the repository at this point in the history
We currently provide both StorageClass and StorageRequest that can be
propagated to the underlying instances.
However, it might be possible that operators use extraMounts to plug a
NFS share mapped to /var/lib/glance.
In this case, the API should be updated to not provision any PVC and
let the human operator to take care about it using the extraMounts
interface.
This patch adds a "Storage" struct that is supposed to act as the high
level interface where the storage strategy for glance is specified.
If the ephemeral boolean is set, no PVCs are provisioned.

Signed-off-by: Francesco Pantano <[email protected]>
  • Loading branch information
fmount committed Jun 11, 2024
1 parent c187e2c commit 3537fdc
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 84 deletions.
18 changes: 9 additions & 9 deletions api/bases/glance.openstack.org_glanceapis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ spec:
type: string
databaseHostname:
type: string
ephemeral:
default: false
type: boolean
extraMounts:
items:
properties:
Expand Down Expand Up @@ -907,8 +904,6 @@ spec:
default: GlancePassword
type: string
type: object
pvc:
type: string
quota:
default: false
type: boolean
Expand Down Expand Up @@ -956,10 +951,15 @@ spec:
serviceUser:
default: glance
type: string
storageClass:
type: string
storageRequest:
type: string
storage:
properties:
ephemeral:
type: boolean
storageClass:
type: string
storageRequest:
type: string
type: object
tls:
properties:
api:
Expand Down
34 changes: 18 additions & 16 deletions api/bases/glance.openstack.org_glances.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ spec:
default: 1 0 * * *
type: string
type: object
ephemeral:
default: false
type: boolean
extraMounts:
items:
properties:
Expand Down Expand Up @@ -836,9 +833,6 @@ spec:
items:
type: string
type: array
ephemeral:
default: false
type: boolean
imageCache:
properties:
cleanerScheduler:
Expand Down Expand Up @@ -912,8 +906,6 @@ spec:
type: object
type: object
type: object
pvc:
type: string
replicas:
default: 1
format: int32
Expand Down Expand Up @@ -951,10 +943,15 @@ spec:
x-kubernetes-int-or-string: true
type: object
type: object
storageClass:
type: string
storageRequest:
type: string
storage:
properties:
ephemeral:
type: boolean
storageClass:
type: string
storageRequest:
type: string
type: object
tls:
properties:
api:
Expand Down Expand Up @@ -1044,10 +1041,15 @@ spec:
serviceUser:
default: glance
type: string
storageClass:
type: string
storageRequest:
type: string
storage:
properties:
ephemeral:
type: boolean
storageClass:
type: string
storageRequest:
type: string
type: object
required:
- containerImage
- databaseInstance
Expand Down
30 changes: 15 additions & 15 deletions api/v1beta1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ type GlanceAPITemplate struct {
// NodeSelector to target subset of worker nodes running this service
NodeSelector map[string]string `json:"nodeSelector,omitempty"`

// +kubebuilder:validation:Optional
// Pvc - Storage claim for file-backed Glance
Pvc string `json:"pvc,omitempty"`

// +kubebuilder:validation:Optional
// CustomServiceConfig - customize the service config using this parameter to change service defaults,
// or overwrite rendered information using raw OpenStack config format. The content gets added to
Expand All @@ -88,17 +84,8 @@ type GlanceAPITemplate struct {
// Override, provides the ability to override the generated manifest of several child resources.
Override APIOverrideSpec `json:"override,omitempty"`

// +kubebuilder:validation:Optional
// StorageClass -
StorageClass string `json:"storageClass,omitempty"`

// StorageRequest -
StorageRequest string `json:"storageRequest,omitempty"`

// +kubebuilder:validation:Optional
// +kubebuilder:default=false
// Ephemeral -
Ephemeral bool `json:"ephemeral"`
// Storage -
Storage Storage `json:"storage,omitempty"`

// +kubebuilder:validation:Enum=split;single;edge
// +kubebuilder:default:=split
Expand All @@ -121,6 +108,19 @@ type GlanceAPITemplate struct {
APITimeout int `json:"apiTimeout,omitempty"`
}

type Storage struct {
// +kubebuilder:validation:Optional
// StorageClass -
StorageClass string `json:"storageClass,omitempty"`

// StorageRequest -
StorageRequest string `json:"storageRequest,omitempty"`

// +kubebuilder:validation:Optional
// Ephemeral -
Ephemeral bool `json:"ephemeral,omitempty"`
}

// ImageCache - struct where the exposed imageCache params are defined
type ImageCache struct {
// Size - Local storage request, in bytes. (500Gi = 500GiB = 500 * 1024 * 1024 * 1024)
Expand Down
14 changes: 2 additions & 12 deletions api/v1beta1/glance_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,8 @@ type GlanceSpecCore struct {
// /etc/<service>/<service>.conf.d directory as a custom config file.
CustomServiceConfigSecrets []string `json:"customServiceConfigSecrets,omitempty"`

// +kubebuilder:validation:Optional
// StorageClass
StorageClass string `json:"storageClass,omitempty"`

// +kubebuilder:validation:Optional
// StorageRequest
StorageRequest string `json:"storageRequest,omitempty"`

// Ephemeral -
// +kubebuilder:validation:Optional
// +kubebuilder:default=false
Ephemeral bool `json:"ephemeral"`
// Storage -
Storage Storage `json:"storage,omitempty"`

// +kubebuilder:validation:Required
// +kubebuilder:default={}
Expand Down
17 changes: 17 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

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

18 changes: 9 additions & 9 deletions config/crd/bases/glance.openstack.org_glanceapis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ spec:
type: string
databaseHostname:
type: string
ephemeral:
default: false
type: boolean
extraMounts:
items:
properties:
Expand Down Expand Up @@ -907,8 +904,6 @@ spec:
default: GlancePassword
type: string
type: object
pvc:
type: string
quota:
default: false
type: boolean
Expand Down Expand Up @@ -956,10 +951,15 @@ spec:
serviceUser:
default: glance
type: string
storageClass:
type: string
storageRequest:
type: string
storage:
properties:
ephemeral:
type: boolean
storageClass:
type: string
storageRequest:
type: string
type: object
tls:
properties:
api:
Expand Down
34 changes: 18 additions & 16 deletions config/crd/bases/glance.openstack.org_glances.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ spec:
default: 1 0 * * *
type: string
type: object
ephemeral:
default: false
type: boolean
extraMounts:
items:
properties:
Expand Down Expand Up @@ -836,9 +833,6 @@ spec:
items:
type: string
type: array
ephemeral:
default: false
type: boolean
imageCache:
properties:
cleanerScheduler:
Expand Down Expand Up @@ -912,8 +906,6 @@ spec:
type: object
type: object
type: object
pvc:
type: string
replicas:
default: 1
format: int32
Expand Down Expand Up @@ -951,10 +943,15 @@ spec:
x-kubernetes-int-or-string: true
type: object
type: object
storageClass:
type: string
storageRequest:
type: string
storage:
properties:
ephemeral:
type: boolean
storageClass:
type: string
storageRequest:
type: string
type: object
tls:
properties:
api:
Expand Down Expand Up @@ -1044,10 +1041,15 @@ spec:
serviceUser:
default: glance
type: string
storageClass:
type: string
storageRequest:
type: string
storage:
properties:
ephemeral:
type: boolean
storageClass:
type: string
storageRequest:
type: string
type: object
required:
- containerImage
- databaseInstance
Expand Down
12 changes: 9 additions & 3 deletions controllers/glance_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -855,9 +855,15 @@ func (r *GlanceReconciler) apiDeploymentCreateOrUpdate(
}

// Inherit the values required for PVC creation from the top-level CR
apiSpec.GlanceAPITemplate.StorageRequest = instance.Spec.StorageRequest
apiSpec.GlanceAPITemplate.StorageClass = instance.Spec.StorageClass
apiSpec.GlanceAPITemplate.Ephemeral = instance.Spec.Ephemeral
if apiSpec.GlanceAPITemplate.Storage.StorageRequest == "" {
apiSpec.GlanceAPITemplate.Storage.StorageRequest = instance.Spec.Storage.StorageRequest
}
if apiSpec.GlanceAPITemplate.Storage.StorageClass == "" {
apiSpec.GlanceAPITemplate.Storage.StorageClass = instance.Spec.Storage.StorageClass
}
if !apiSpec.GlanceAPITemplate.Storage.Ephemeral {
apiSpec.GlanceAPITemplate.Storage.Ephemeral = instance.Spec.Storage.Ephemeral
}

apiSpec.MemcachedInstance = memcached.Name
// Make sure to inject the ContainerImage passed by the OpenStackVersions
Expand Down
4 changes: 2 additions & 2 deletions pkg/glance/pvc.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func GetPvc(api *glancev1.GlanceAPI, labels map[string]string, pvcType PvcType)
pvcName = fmt.Sprintf("%s-cache", ServiceName)
default:
pvcName = ServiceName
requestSize = api.Spec.StorageRequest
requestSize = api.Spec.Storage.StorageRequest
}
// Build the basic pvc object
pvc := corev1.PersistentVolumeClaim{
Expand Down Expand Up @@ -54,7 +54,7 @@ func GetPvc(api *glancev1.GlanceAPI, labels map[string]string, pvcType PvcType)
corev1.ResourceStorage: storageSize,
},
},
StorageClassName: &api.Spec.StorageClass,
StorageClassName: &api.Spec.Storage.StorageClass,
}

return pvc, err
Expand Down
4 changes: 2 additions & 2 deletions pkg/glanceapi/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func StatefulSet(
VolumeMounts: append(glance.GetVolumeMounts(
instance.Spec.CustomServiceConfigSecrets,
privileged,
instance.Spec.Ephemeral,
instance.Spec.Storage.Ephemeral,
instance.Spec.ExtraMounts,
extraVolPropagation),
apiVolumeMounts...,
Expand All @@ -305,7 +305,7 @@ func StatefulSet(
},
}
var err error
if !instance.Spec.Ephemeral {
if !instance.Spec.Storage.Ephemeral {
localPvc, err := glance.GetPvc(instance, labels, glance.PvcLocal)
if err != nil {
return statefulset, err
Expand Down

0 comments on commit 3537fdc

Please sign in to comment.