Skip to content

Commit

Permalink
Rename InstanceHA to InstanceHa and use configmap for containerImage
Browse files Browse the repository at this point in the history
This commit renames the InstanceHA occurrences into InstanceHa
to comply with the openstack-operator's openstackversion naming
(case) convention.

We also take the chance and use a configmap created by
the openstack-operator to get the containerImage, so
to orchestrate its update.
  • Loading branch information
lmiccini committed Sep 12, 2024
1 parent 31f905c commit 387ae23
Show file tree
Hide file tree
Showing 13 changed files with 213 additions and 181 deletions.
2 changes: 1 addition & 1 deletion PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ resources:
controller: true
domain: openstack.org
group: instanceha
kind: InstanceHA
kind: InstanceHa
path: github.com/openstack-k8s-operators/infra-operator/apis/instanceha/v1beta1
version: v1beta1
webhooks:
Expand Down
24 changes: 12 additions & 12 deletions apis/bases/instanceha.openstack.org_instancehas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ metadata:
spec:
group: instanceha.openstack.org
names:
kind: InstanceHA
listKind: InstanceHAList
kind: InstanceHa
listKind: InstanceHaList
plural: instancehas
singular: instanceha
scope: Namespaced
Expand All @@ -27,7 +27,7 @@ spec:
name: v1beta1
schema:
openAPIV3Schema:
description: InstanceHA is the Schema for the instancehas API
description: InstanceHa is the Schema for the instancehas API
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
Expand All @@ -42,28 +42,28 @@ spec:
metadata:
type: object
spec:
description: InstanceHASpec defines the desired state of InstanceHA
description: InstanceHaSpec defines the desired state of InstanceHa
properties:
caBundleSecretName:
description: CaBundleSecretName - holding the CA certs in a pre-created
bundle file
type: string
containerImage:
default: quay.io/podified-antelope-centos9/openstack-openstackclient:current-podified
description: ContainerImage for the the InstanceHA container (will
description: ContainerImage for the the InstanceHa container (will
be set to environmental default if empty)
type: string
fencingSecret:
default: fencing-secret
description: FencingSecret is the name of the Secret containing the
fencing details
type: string
instanceHAConfigMap:
instanceHaConfigMap:
default: instanceha-config
description: InstanceHAConfigMap is the name of the ConfigMap containing
the InstanceHA config file
description: InstanceHaConfigMap is the name of the ConfigMap containing
the InstanceHa config file
type: string
instanceHAKdumpPort:
instanceHaKdumpPort:
default: 7410
format: int32
type: integer
Expand Down Expand Up @@ -98,14 +98,14 @@ spec:
required:
- containerImage
- fencingSecret
- instanceHAConfigMap
- instanceHAKdumpPort
- instanceHaConfigMap
- instanceHaKdumpPort
- openStackCloud
- openStackConfigMap
- openStackConfigSecret
type: object
status:
description: InstanceHAStatus defines the observed state of InstanceHA
description: InstanceHaStatus defines the observed state of InstanceHa
properties:
conditions:
description: Conditions
Expand Down
36 changes: 18 additions & 18 deletions apis/instanceha/v1beta1/instanceha_conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,35 @@ import (
condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
)

// InstanceHA Condition Types used by API objects.
// InstanceHa Condition Types used by API objects.
const (
// InstanceHAReadyCondition Status=True condition which indicates if InstanceHA is configured and operational
InstanceHAReadyCondition condition.Type = "InstanceHAReady"
// InstanceHaReadyCondition Status=True condition which indicates if InstanceHa is configured and operational
InstanceHaReadyCondition condition.Type = "InstanceHaReady"
)

// InstanceHA Reasons used by API objects.
// InstanceHa Reasons used by API objects.
const ()

// Common Messages used by API objects.
const (
// InstanceHAReadyInitMessage
InstanceHAReadyInitMessage = "Instance HA not started, waiting on keystone API"
// InstanceHaReadyInitMessage
InstanceHaReadyInitMessage = "Instance HA not started, waiting on keystone API"

// InstanceHAKeystoneWaitingMessage
InstanceHAKeystoneWaitingMessage = "Instance HA keystone API not yet ready"
// InstanceHaKeystoneWaitingMessage
InstanceHaKeystoneWaitingMessage = "Instance HA keystone API not yet ready"

// InstanceHAConfigMapWaitingMessage
InstanceHAConfigMapWaitingMessage = "Instance HA waiting for configmap"
// InstanceHaConfigMapWaitingMessage
InstanceHaConfigMapWaitingMessage = "Instance HA waiting for configmap"

// InstanceHASecretWaitingMessage
InstanceHASecretWaitingMessage = "Instance HA waiting for secret"
// InstanceHaSecretWaitingMessage
InstanceHaSecretWaitingMessage = "Instance HA waiting for secret"

// InstanceHAInputReady
InstanceHAInputReady = "Instance HA input ready"
// InstanceHaInputReady
InstanceHaInputReady = "Instance HA input ready"

// InstanceHAReadyMessage
InstanceHAReadyMessage = "Instance HA created"
// InstanceHaReadyMessage
InstanceHaReadyMessage = "Instance HA created"

// InstanceHAReadyErrorMessage
InstanceHAReadyErrorMessage = "Instance HA error occured %s"
// InstanceHaReadyErrorMessage
InstanceHaReadyErrorMessage = "Instance HA error occured %s"
)
50 changes: 25 additions & 25 deletions apis/instanceha/v1beta1/instanceha_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ import (
const (
// Container image fall-back defaults

// InstanceHAContainerImage is the fall-back container image for InstanceHA
InstanceHAContainerImage = "quay.io/podified-antelope-centos9/openstack-openstackclient:current-podified"
// InstanceHaContainerImage is the fall-back container image for InstanceHa
InstanceHaContainerImage = "quay.io/podified-antelope-centos9/openstack-openstackclient:current-podified"
OpenStackCloud = "default"
)

// InstanceHASpec defines the desired state of InstanceHA
type InstanceHASpec struct {
// InstanceHaSpec defines the desired state of InstanceHa
type InstanceHaSpec struct {
// +kubebuilder:validation:Required
// +kubebuilder:default="quay.io/podified-antelope-centos9/openstack-openstackclient:current-podified"
// ContainerImage for the the InstanceHA container (will be set to environmental default if empty)
// ContainerImage for the the InstanceHa container (will be set to environmental default if empty)
ContainerImage string `json:"containerImage"`

// +kubebuilder:validation:Required
Expand All @@ -60,12 +60,12 @@ type InstanceHASpec struct {

// +kubebuilder:validation:Required
// +kubebuilder:default=instanceha-config
// InstanceHAConfigMap is the name of the ConfigMap containing the InstanceHA config file
InstanceHAConfigMap string `json:"instanceHAConfigMap"`
// InstanceHaConfigMap is the name of the ConfigMap containing the InstanceHa config file
InstanceHaConfigMap string `json:"instanceHaConfigMap"`

// +kubebuilder:validation:Required
// +kubebuilder:default=7410
InstanceHAKdumpPort int32 `json:"instanceHAKdumpPort"`
InstanceHaKdumpPort int32 `json:"instanceHaKdumpPort"`

// +kubebuilder:validation:Optional
// NodeSelector to target subset of worker nodes running control plane services (currently only applies to KeystoneAPI and PlacementAPI)
Expand All @@ -82,8 +82,8 @@ type InstanceHASpec struct {
tls.Ca `json:",inline"`
}

// InstanceHAStatus defines the observed state of InstanceHA
type InstanceHAStatus struct {
// InstanceHaStatus defines the observed state of InstanceHa
type InstanceHaStatus struct {
// PodName
PodName string `json:"podName,omitempty"`

Expand All @@ -102,49 +102,49 @@ type InstanceHAStatus struct {
//+kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.conditions[0].status",description="Status"
//+kubebuilder:printcolumn:name="Message",type="string",JSONPath=".status.conditions[0].message",description="Message"

// InstanceHA is the Schema for the instancehas API
type InstanceHA struct {
// InstanceHa is the Schema for the instancehas API
type InstanceHa struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec InstanceHASpec `json:"spec,omitempty"`
Status InstanceHAStatus `json:"status,omitempty"`
Spec InstanceHaSpec `json:"spec,omitempty"`
Status InstanceHaStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// InstanceHAList contains a list of InstanceHA
type InstanceHAList struct {
// InstanceHaList contains a list of InstanceHa
type InstanceHaList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []InstanceHA `json:"items"`
Items []InstanceHa `json:"items"`
}

func init() {
SchemeBuilder.Register(&InstanceHA{}, &InstanceHAList{})
SchemeBuilder.Register(&InstanceHa{}, &InstanceHaList{})
}

// RbacConditionsSet - set the conditions for the rbac object
func (instance InstanceHA) RbacConditionsSet(c *condition.Condition) {
func (instance InstanceHa) RbacConditionsSet(c *condition.Condition) {
instance.Status.Conditions.Set(c)
}

// RbacNamespace - return the namespace
func (instance InstanceHA) RbacNamespace() string {
func (instance InstanceHa) RbacNamespace() string {
return instance.Namespace
}

// RbacResourceName - return the name to be used for rbac objects (serviceaccount, role, rolebinding)
func (instance InstanceHA) RbacResourceName() string {
func (instance InstanceHa) RbacResourceName() string {
return "instanceha-" + instance.Name
}

// SetupDefaults - initializes any CRD field defaults based on environment variables (the defaulting mechanism itself is implemented via webhooks)
func SetupDefaults() {
// Acquire environmental defaults and initialize InstanceHA defaults with them
instanceHADefaults := InstanceHADefaults{
ContainerImageURL: util.GetEnvVar("RELATED_IMAGE_INSTANCE_HA_IMAGE_URL_DEFAULT", InstanceHAContainerImage),
// Acquire environmental defaults and initialize InstanceHa defaults with them
instanceHaDefaults := InstanceHaDefaults{
ContainerImageURL: util.GetEnvVar("RELATED_IMAGE_INSTANCE_HA_IMAGE_URL_DEFAULT", InstanceHaContainerImage),
}

SetupInstanceHADefaults(instanceHADefaults)
SetupInstanceHaDefaults(instanceHaDefaults)
}
36 changes: 18 additions & 18 deletions apis/instanceha/v1beta1/instanceha_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ limitations under the License.
//
// Generated by:
//
// operator-sdk create webhook --group client --version v1beta1 --kind InstanceHA --programmatic-validation --defaulting
// operator-sdk create webhook --group client --version v1beta1 --kind InstanceHa --programmatic-validation --defaulting
//

package v1beta1
Expand All @@ -27,70 +27,70 @@ import (
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

// InstanceHADefaults -
type InstanceHADefaults struct {
// InstanceHaDefaults -
type InstanceHaDefaults struct {
ContainerImageURL string
}

var instanceHADefaults InstanceHADefaults
var instanceHaDefaults InstanceHaDefaults

// log is for logging in this package.
var instancehalog = logf.Log.WithName("instanceha-resource")

// SetupInstanceHADefaults - initialize InstanceHA spec defaults for use with either internal or external webhooks
func SetupInstanceHADefaults(defaults InstanceHADefaults) {
instanceHADefaults = defaults
instancehalog.Info("InstanceHA defaults initialized", "defaults", defaults)
// SetupInstanceHaDefaults - initialize InstanceHa spec defaults for use with either internal or external webhooks
func SetupInstanceHaDefaults(defaults InstanceHaDefaults) {
instanceHaDefaults = defaults
instancehalog.Info("InstanceHa defaults initialized", "defaults", defaults)
}

// SetupWebhookWithManager sets up the webhook with the Manager
func (r *InstanceHA) SetupWebhookWithManager(mgr ctrl.Manager) error {
func (r *InstanceHa) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).
For(r).
Complete()
}

//+kubebuilder:webhook:path=/mutate-client-openstack-org-v1beta1-instanceha,mutating=true,failurePolicy=fail,sideEffects=None,groups=client.openstack.org,resources=instancehas,verbs=create;update,versions=v1beta1,name=minstanceha.kb.io,admissionReviewVersions=v1

var _ webhook.Defaulter = &InstanceHA{}
var _ webhook.Defaulter = &InstanceHa{}

// Default implements webhook.Defaulter so a webhook will be registered for the type
func (r *InstanceHA) Default() {
func (r *InstanceHa) Default() {
instancehalog.Info("default", "name", r.Name)

r.Spec.Default()
}

// Default - set defaults for this InstanceHA spec
func (spec *InstanceHASpec) Default() {
// Default - set defaults for this InstanceHa spec
func (spec *InstanceHaSpec) Default() {
if spec.ContainerImage == "" {
spec.ContainerImage = instanceHADefaults.ContainerImageURL
spec.ContainerImage = instanceHaDefaults.ContainerImageURL
}
}

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

var _ webhook.Validator = &InstanceHA{}
var _ webhook.Validator = &InstanceHa{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
func (r *InstanceHA) ValidateCreate() (admission.Warnings, error) {
func (r *InstanceHa) ValidateCreate() (admission.Warnings, error) {
instancehalog.Info("validate create", "name", r.Name)

// TODO(user): fill in your validation logic upon object creation.
return nil, nil
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
func (r *InstanceHA) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
func (r *InstanceHa) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
instancehalog.Info("validate update", "name", r.Name)

// TODO(user): fill in your validation logic upon object update.
return nil, nil
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
func (r *InstanceHA) ValidateDelete() (admission.Warnings, error) {
func (r *InstanceHa) ValidateDelete() (admission.Warnings, error) {
instancehalog.Info("validate delete", "name", r.Name)

// TODO(user): fill in your validation logic upon object deletion.
Expand Down
2 changes: 1 addition & 1 deletion apis/instanceha/v1beta1/webhook_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ var _ = BeforeSuite(func() {
})
Expect(err).NotTo(HaveOccurred())

err = (&InstanceHA{}).SetupWebhookWithManager(mgr)
err = (&InstanceHa{}).SetupWebhookWithManager(mgr)
Expect(err).NotTo(HaveOccurred())

//+kubebuilder:scaffold:webhook
Expand Down
Loading

0 comments on commit 387ae23

Please sign in to comment.