Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webhook for default images #25

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,9 @@ SKIP_CERT ?=false
.PHONY: run-with-webhook
run-with-webhook: export METRICS_PORT?=33080
run-with-webhook: export HEALTH_PORT?=33081
run-with-webhook: export WATCHER_API_IMAGE_URL_DEFAULT=quay.io/podified-main-centos9/openstack-watcher-api:current-podified
run-with-webhook: export WATCHER_DECISION_ENGINE_IMAGE_URL_DEFAULT=quay.io/podified-main-centos9/openstack-watcher-decision-engine:current-podified
run-with-webhook: export WATCHER_APPLIER_IMAGE_URL_DEFAULT=quay.io/podified-main-centos9/openstack-watcher-applier:current-podified
run-with-webhook: manifests generate fmt vet ## Run a controller from your host.
/bin/bash hack/clean_local_webhook.sh
/bin/bash hack/run_with_local_webhook.sh
Expand Down
4 changes: 4 additions & 0 deletions api/bases/watcher.openstack.org_watcherapis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ spec:
spec:
description: WatcherAPISpec defines the desired state of WatcherAPI
properties:
containerImage:
description: The service specific Container Image URL (will be set
to environmental default if empty)
type: string
databaseAccount:
default: watcher
description: DatabaseAccount - MariaDBAccount CR name used for watcher
Expand Down
6 changes: 3 additions & 3 deletions api/bases/watcher.openstack.org_watcherappliers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ spec:
spec:
description: WatcherApplierSpec defines the desired state of WatcherApplier
properties:
foo:
description: Foo is an example field of WatcherApplier. Edit watcherapplier_types.go
to remove/update
containerImage:
description: The service specific Container Image URL (will be set
to environmental default if empty)
type: string
type: object
status:
Expand Down
6 changes: 3 additions & 3 deletions api/bases/watcher.openstack.org_watcherdecisionengines.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ spec:
spec:
description: WatcherDecisionEngineSpec defines the desired state of WatcherDecisionEngine
properties:
foo:
description: Foo is an example field of WatcherDecisionEngine. Edit
watcherdecisionengine_types.go to remove/update
containerImage:
description: The service specific Container Image URL (will be set
to environmental default if empty)
type: string
type: object
status:
Expand Down
12 changes: 12 additions & 0 deletions api/bases/watcher.openstack.org_watchers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ spec:
spec:
description: WatcherSpec defines the desired state of Watcher
properties:
apiContainerImageURL:
description: APIContainerImageURL
type: string
applierContainerImageURL:
description: ApplierContainerImageURL
type: string
databaseAccount:
default: watcher
description: DatabaseAccount - MariaDBAccount CR name used for watcher
Expand All @@ -49,6 +55,9 @@ spec:
MariaDB instance name
Required to use the mariadb-operator instance to create the DB and user
type: string
decisionengineContainerImageURL:
description: DecisionEngineContainerImageURL
type: string
memcachedInstance:
default: memcached
description: MemcachedInstance is the name of the Memcached CR that
Expand Down Expand Up @@ -82,7 +91,10 @@ spec:
to register in keystone
type: string
required:
- apiContainerImageURL
- applierContainerImageURL
- databaseInstance
- decisionengineContainerImageURL
- rabbitMqClusterName
type: object
status:
Expand Down
54 changes: 54 additions & 0 deletions api/v1beta1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ limitations under the License.

package v1beta1

import "github.com/openstack-k8s-operators/lib-common/modules/common/util"

// Container image fall-back defaults
const (
WatcherAPIContainerImage = "quay.io/podified-antelope-centos9/openstack-watcher-api:current-podified"
WatcherDecisionEngineContainerImage = "quay.io/podified-antelope-centos9/openstack-watcher-decision-engine:current-podified"
WatcherApplierContainerImage = "quay.io/podified-antelope-centos9/openstack-watcher-applier:current-podified"
)

// WatcherCommon defines a spec based reusable for all the CRDs
type WatcherCommon struct {

Expand Down Expand Up @@ -70,3 +79,48 @@ type PasswordSelector struct {
// Service - Selector to get the watcher service user password from the Secret
Service string `json:"service"`
}

// WatcherSubCrsCommon
type WatcherSubCrsCommon struct {
// +kubebuilder:validation:Optional
// The service specific Container Image URL (will be set to environmental default if empty)
ContainerImage string `json:"containerImage"`
}

type WatcherImages struct {
// +kubebuilder:validation:Required
amoralej marked this conversation as resolved.
Show resolved Hide resolved
// APIContainerImageURL
APIContainerImageURL string `json:"apiContainerImageURL"`

// +kubebuilder:validation:Required
// DecisionEngineContainerImageURL
DecisionEngineContainerImageURL string `json:"decisionengineContainerImageURL"`

// +kubebuilder:validation:Required
// ApplierContainerImageURL
ApplierContainerImageURL string `json:"applierContainerImageURL"`
}

func (r *WatcherImages) Default(defaults WatcherDefaults) {
if r.APIContainerImageURL == "" {
r.APIContainerImageURL = defaults.APIContainerImageURL
}
if r.DecisionEngineContainerImageURL == "" {
r.DecisionEngineContainerImageURL = defaults.DecisionEngineContainerImageURL
}
if r.ApplierContainerImageURL == "" {
r.ApplierContainerImageURL = defaults.ApplierContainerImageURL
}
}

// SetupDefaults - initializes any CRD field defaults based on environment variables (the defaulting mechanism itself is implemented via webhooks)

func SetupDefaults() {
amoralej marked this conversation as resolved.
Show resolved Hide resolved
// Acquire environmental defaults and initialize Nova defaults with them
watcherDefaults := WatcherDefaults{
APIContainerImageURL: util.GetEnvVar("WATCHER_API_IMAGE_URL_DEFAULT", WatcherAPIContainerImage),
ApplierContainerImageURL: util.GetEnvVar("WATCHER_APPLIER_IMAGE_URL_DEFAULT", WatcherApplierContainerImage),
DecisionEngineContainerImageURL: util.GetEnvVar("WATCHER_DECISION_ENGINE_IMAGE_URL_DEFAULT", WatcherDecisionEngineContainerImage),
}
SetupWatcherDefaults(watcherDefaults)
}
7 changes: 3 additions & 4 deletions api/v1beta1/watcher_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ type WatcherSpec struct {
// Important: Run "make" to regenerate code after modifying this file

WatcherTemplate `json:",inline"`

// +kubebuilder:validation:Required
WatcherImages `json:",inline"`
}

// WatcherStatus defines the observed state of Watcher
Expand Down Expand Up @@ -68,7 +71,3 @@ type WatcherList struct {
func init() {
SchemeBuilder.Register(&Watcher{}, &WatcherList{})
}

// SetupDefaults - initializes any CRD field defaults based on environment variables (the defaulting mechanism itself is implemented via webhooks)
func SetupDefaults() {
}
20 changes: 20 additions & 0 deletions api/v1beta1/watcher_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,23 @@ import (
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

// WatcherDefaults -
type WatcherDefaults struct {
APIContainerImageURL string
DecisionEngineContainerImageURL string
ApplierContainerImageURL string
}

var watcherDefaults WatcherDefaults

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

func SetupWatcherDefaults(defaults WatcherDefaults) {
watcherDefaults = defaults
watcherlog.Info("Watcher defaults initialized", "defaults", defaults)
}

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

var _ webhook.Defaulter = &Watcher{}
Expand All @@ -34,6 +48,12 @@ var _ webhook.Defaulter = &Watcher{}
func (r *Watcher) Default() {
watcherlog.Info("default", "name", r.Name)

amoralej marked this conversation as resolved.
Show resolved Hide resolved
r.Spec.Default()
}

// Default - set defaults for this WatcherCore spec.
func (spec *WatcherSpec) Default() {
spec.WatcherImages.Default(watcherDefaults)
}

//+kubebuilder:webhook:path=/validate-watcher-openstack-org-v1beta1-watcher,mutating=false,failurePolicy=fail,sideEffects=None,groups=watcher.openstack.org,resources=watchers,verbs=create;update,versions=v1beta1,name=vwatcher.kb.io,admissionReviewVersions=v1
Expand Down
2 changes: 2 additions & 0 deletions api/v1beta1/watcherapi_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ type WatcherAPISpec struct {
// +kubebuilder:validation:Required
// Secret containing all passwords / keys needed
Secret string `json:"secret"`

WatcherSubCrsCommon `json:",inline"`
}

// WatcherAPIStatus defines the observed state of WatcherAPI
Expand Down
3 changes: 1 addition & 2 deletions api/v1beta1/watcherapplier_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ type WatcherApplierSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

// Foo is an example field of WatcherApplier. Edit watcherapplier_types.go to remove/update
Foo string `json:"foo,omitempty"`
WatcherSubCrsCommon `json:",inline"`
}

// WatcherApplierStatus defines the observed state of WatcherApplier
Expand Down
3 changes: 1 addition & 2 deletions api/v1beta1/watcherdecisionengine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ type WatcherDecisionEngineSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

// Foo is an example field of WatcherDecisionEngine. Edit watcherdecisionengine_types.go to remove/update
Foo string `json:"foo,omitempty"`
WatcherSubCrsCommon `json:",inline"`
}

// WatcherDecisionEngineStatus defines the observed state of WatcherDecisionEngine
Expand Down
49 changes: 49 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.

4 changes: 4 additions & 0 deletions config/crd/bases/watcher.openstack.org_watcherapis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ spec:
spec:
description: WatcherAPISpec defines the desired state of WatcherAPI
properties:
containerImage:
description: The service specific Container Image URL (will be set
to environmental default if empty)
type: string
databaseAccount:
default: watcher
description: DatabaseAccount - MariaDBAccount CR name used for watcher
Expand Down
6 changes: 3 additions & 3 deletions config/crd/bases/watcher.openstack.org_watcherappliers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ spec:
spec:
description: WatcherApplierSpec defines the desired state of WatcherApplier
properties:
foo:
description: Foo is an example field of WatcherApplier. Edit watcherapplier_types.go
to remove/update
containerImage:
description: The service specific Container Image URL (will be set
to environmental default if empty)
type: string
type: object
status:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ spec:
spec:
description: WatcherDecisionEngineSpec defines the desired state of WatcherDecisionEngine
properties:
foo:
description: Foo is an example field of WatcherDecisionEngine. Edit
watcherdecisionengine_types.go to remove/update
containerImage:
description: The service specific Container Image URL (will be set
to environmental default if empty)
type: string
type: object
status:
Expand Down
12 changes: 12 additions & 0 deletions config/crd/bases/watcher.openstack.org_watchers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ spec:
spec:
description: WatcherSpec defines the desired state of Watcher
properties:
apiContainerImageURL:
description: APIContainerImageURL
type: string
applierContainerImageURL:
description: ApplierContainerImageURL
type: string
databaseAccount:
default: watcher
description: DatabaseAccount - MariaDBAccount CR name used for watcher
Expand All @@ -49,6 +55,9 @@ spec:
MariaDB instance name
Required to use the mariadb-operator instance to create the DB and user
type: string
decisionengineContainerImageURL:
description: DecisionEngineContainerImageURL
type: string
memcachedInstance:
default: memcached
description: MemcachedInstance is the name of the Memcached CR that
Expand Down Expand Up @@ -82,7 +91,10 @@ spec:
to register in keystone
type: string
required:
- apiContainerImageURL
- applierContainerImageURL
- databaseInstance
- decisionengineContainerImageURL
- rabbitMqClusterName
type: object
status:
Expand Down
Loading
Loading