Skip to content

Commit

Permalink
Create the required mariadb database and account for watcher
Browse files Browse the repository at this point in the history
This patch is adding the database and db accout creation to the watcher
controller.

It adds the required CR spec and status, and create the initial
structura for initialization and deletion.

Finally, it is also creating the initial structure for functional envtest
tests.

Related: OSPRH-11422
  • Loading branch information
amoralej committed Nov 20, 2024
1 parent 29c4598 commit 278440b
Show file tree
Hide file tree
Showing 15 changed files with 1,118 additions and 95 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ PROC_CMD = --procs ${PROCS}

.PHONY: test
test: manifests generate fmt vet envtest ginkgo ## Run tests.
@echo "TODO add test execution"
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" $(GINKGO) --trace --cover --coverpkg=../../pkg/watcher,../../controllers,../../api/v1beta1 --coverprofile cover.out --covermode=atomic ${PROC_CMD} $(GINKGO_ARGS) ./tests/...


##@ Build

Expand Down Expand Up @@ -238,6 +239,7 @@ ginkgo: $(GINKGO) ## Download ginkgo locally if necessary.
$(GINKGO): $(LOCALBIN)
test -s $(LOCALBIN)/ginkgo || GOBIN=$(LOCALBIN) go install github.com/onsi/ginkgo/v2/ginkgo


.PHONY: operator-sdk
OPERATOR_SDK ?= $(LOCALBIN)/operator-sdk
operator-sdk: ## Download operator-sdk locally if necessary.
Expand Down
89 changes: 86 additions & 3 deletions api/bases/watcher.openstack.org_watchers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,96 @@ spec:
spec:
description: WatcherSpec defines the desired state of Watcher
properties:
foo:
description: Foo is an example field of Watcher. Edit watcher_types.go
to remove/update
databaseAccount:
default: watcher
description: DatabaseAccount - MariaDBAccount CR name used for watcher
DB, defaults to watcher
type: string
databaseInstance:
description: MariaDB instance name Required to use the maridb-operator
instance to create the DB and user
type: string
passwordSelectors:
default:
service: WatcherPassword
description: PasswordSelectors - Selectors to identify the ServiceUser
password from the Secret
properties:
service:
default: WatcherPassword
description: Service - Selector to get the watcher service user
password from the Secret
type: string
type: object
secret:
default: osp-secret
description: Secret containing all passwords / keys needed
type: string
required:
- databaseInstance
type: object
status:
description: WatcherStatus defines the observed state of Watcher
properties:
conditions:
description: Conditions
items:
description: Condition defines an observation of a API resource
operational state.
properties:
lastTransitionTime:
description: Last time the condition transitioned from one status
to another. This should be when the underlying condition changed.
If that is not known, then using the time when the API field
changed is acceptable.
format: date-time
type: string
message:
description: A human readable message indicating details about
the transition.
type: string
reason:
description: The reason for the condition's last transition
in CamelCase.
type: string
severity:
description: Severity provides a classification of Reason code,
so the current situation is immediately understandable and
could act accordingly. It is meant for situations where Status=False
and it should be indicated if it is just informational, warning
(next reconciliation might fix it) or an error (e.g. DB create
issue and no actions to automatically resolve the issue can/should
be done). For conditions where Status=Unknown or Status=True
the Severity should be SeverityNone.
type: string
status:
description: Status of the condition, one of True, False, Unknown.
type: string
type:
description: Type of condition in CamelCase.
type: string
required:
- lastTransitionTime
- status
- type
type: object
type: array
databaseHostname:
description: Watcher Database Hostname
type: string
hash:
additionalProperties:
type: string
description: Map of hashes to track e.g. job status
type: object
observedGeneration:
description: ObservedGeneration - the most recent generation observed
for this service. If the observed generation is less than the spec
generation, then the controller has not processed the latest changes
injected by the opentack-operator in the top-level CR (e.g. the
ContainerImage)
format: int64
type: integer
type: object
type: object
served: true
Expand Down
56 changes: 50 additions & 6 deletions api/v1beta1/watcher_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,65 @@ limitations under the License.
package v1beta1

import (
"github.com/openstack-k8s-operators/lib-common/modules/common/condition"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
const (
// DbSyncHash hash
DbSyncHash = "dbsync"
)

// WatcherSpec defines the desired state of Watcher
type WatcherSpec 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 Watcher. Edit watcher_types.go to remove/update
Foo string `json:"foo,omitempty"`
// +kubebuilder:validation:Optional
// +kubebuilder:default=osp-secret
// Secret containing all passwords / keys needed
Secret string `json:"secret"`

// +kubebuilder:validation:Optional
// +kubebuilder:default={service: WatcherPassword,}
// PasswordSelectors - Selectors to identify the ServiceUser password from the Secret
PasswordSelectors PasswordSelector `json:"passwordSelectors"`

// +kubebuilder:validation:Required
// MariaDB instance name
// Required to use the maridb-operator instance to create the DB and user
DatabaseInstance string `json:"databaseInstance"`

// +kubebuilder:validation:Optional
// +kubebuilder:default=watcher
// DatabaseAccount - MariaDBAccount CR name used for watcher DB, defaults to watcher
DatabaseAccount string `json:"databaseAccount"`
}

// PasswordSelector to identify the DB and AdminUser password from the Secret
type PasswordSelector struct {
// +kubebuilder:validation:Optional
// +kubebuilder:default="WatcherPassword"
// Service - Selector to get the watcher service user password from the Secret
Service string `json:"service"`
}

// WatcherStatus defines the observed state of Watcher
type WatcherStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
// Conditions
Conditions condition.Conditions `json:"conditions,omitempty" optional:"true"`

// ObservedGeneration - the most recent generation observed for this
// service. If the observed generation is less than the spec generation,
// then the controller has not processed the latest changes injected by
// the opentack-operator in the top-level CR (e.g. the ContainerImage)
ObservedGeneration int64 `json:"observedGeneration,omitempty"`

// Watcher Database Hostname
DatabaseHostname string `json:"databaseHostname,omitempty"`

// Map of hashes to track e.g. job status
Hash map[string]string `json:"hash,omitempty"`
}

//+kubebuilder:object:root=true
Expand All @@ -62,3 +102,7 @@ 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() {
}
33 changes: 32 additions & 1 deletion api/v1beta1/zz_generated.deepcopy.go

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

89 changes: 86 additions & 3 deletions config/crd/bases/watcher.openstack.org_watchers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,96 @@ spec:
spec:
description: WatcherSpec defines the desired state of Watcher
properties:
foo:
description: Foo is an example field of Watcher. Edit watcher_types.go
to remove/update
databaseAccount:
default: watcher
description: DatabaseAccount - MariaDBAccount CR name used for watcher
DB, defaults to watcher
type: string
databaseInstance:
description: MariaDB instance name Required to use the maridb-operator
instance to create the DB and user
type: string
passwordSelectors:
default:
service: WatcherPassword
description: PasswordSelectors - Selectors to identify the ServiceUser
password from the Secret
properties:
service:
default: WatcherPassword
description: Service - Selector to get the watcher service user
password from the Secret
type: string
type: object
secret:
default: osp-secret
description: Secret containing all passwords / keys needed
type: string
required:
- databaseInstance
type: object
status:
description: WatcherStatus defines the observed state of Watcher
properties:
conditions:
description: Conditions
items:
description: Condition defines an observation of a API resource
operational state.
properties:
lastTransitionTime:
description: Last time the condition transitioned from one status
to another. This should be when the underlying condition changed.
If that is not known, then using the time when the API field
changed is acceptable.
format: date-time
type: string
message:
description: A human readable message indicating details about
the transition.
type: string
reason:
description: The reason for the condition's last transition
in CamelCase.
type: string
severity:
description: Severity provides a classification of Reason code,
so the current situation is immediately understandable and
could act accordingly. It is meant for situations where Status=False
and it should be indicated if it is just informational, warning
(next reconciliation might fix it) or an error (e.g. DB create
issue and no actions to automatically resolve the issue can/should
be done). For conditions where Status=Unknown or Status=True
the Severity should be SeverityNone.
type: string
status:
description: Status of the condition, one of True, False, Unknown.
type: string
type:
description: Type of condition in CamelCase.
type: string
required:
- lastTransitionTime
- status
- type
type: object
type: array
databaseHostname:
description: Watcher Database Hostname
type: string
hash:
additionalProperties:
type: string
description: Map of hashes to track e.g. job status
type: object
observedGeneration:
description: ObservedGeneration - the most recent generation observed
for this service. If the observed generation is less than the spec
generation, then the controller has not processed the latest changes
injected by the opentack-operator in the top-level CR (e.g. the
ContainerImage)
format: int64
type: integer
type: object
type: object
served: true
Expand Down
30 changes: 30 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,36 @@ metadata:
creationTimestamp: null
name: manager-role
rules:
- apiGroups:
- mariadb.openstack.org
resources:
- mariadbaccounts
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- mariadb.openstack.org
resources:
- mariadbaccounts/finalizers
verbs:
- update
- apiGroups:
- mariadb.openstack.org
resources:
- mariadbdatabases
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- watcher.openstack.org
resources:
Expand Down
Loading

0 comments on commit 278440b

Please sign in to comment.