Skip to content

Commit

Permalink
Add initial watcher api conf generation
Browse files Browse the repository at this point in the history
Implement an initial version of watcher config generation. This change
adds a watcher config template and generates a secret with the templated
config. Some fields that require changes in the watcher controller like
the transporturl and memcached servers.

This change also moidifies the WatcherAPI functional tests so the
WatcherAPI instances use a different name that the Watcher one, so it's
easier to debug.
  • Loading branch information
cescgina committed Dec 17, 2024
1 parent eceb232 commit 48a6210
Show file tree
Hide file tree
Showing 22 changed files with 462 additions and 50 deletions.
11 changes: 9 additions & 2 deletions api/bases/watcher.openstack.org_watcherapis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ spec:
MariaDB instance name
Required to use the mariadb-operator instance to create the DB and user
type: string
memcachedInstance:
description: MemcachedInstance is the name of the Memcached CR that
all watcher service will use.
type: string
passwordSelectors:
default:
service: WatcherPassword
Expand All @@ -66,11 +70,14 @@ spec:
type: string
serviceUser:
default: watcher
description: ServiceUser - optional username used for this service
to register in keystone
description: |-
ServiceUser - optional username used for this service to register in
keystone
type: string
required:
- databaseInstance
- memcachedInstance
- passwordSelectors
- secret
type: object
status:
Expand Down
11 changes: 9 additions & 2 deletions api/bases/watcher.openstack.org_watchers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ spec:
MariaDB instance name
Required to use the mariadb-operator instance to create the DB and user
type: string
memcachedInstance:
default: memcached
description: MemcachedInstance is the name of the Memcached CR that
all watcher service will use.
type: string
passwordSelectors:
default:
service: WatcherPassword
Expand All @@ -73,11 +78,13 @@ spec:
type: string
serviceUser:
default: watcher
description: ServiceUser - optional username used for this service
to register in keystone
description: |-
ServiceUser - optional username used for this service to register in
keystone
type: string
required:
- databaseInstance
- passwordSelectors
- rabbitMqClusterName
type: object
status:
Expand Down
3 changes: 2 additions & 1 deletion api/v1beta1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ type WatcherCommon struct {

// +kubebuilder:validation:Optional
// +kubebuilder:default=watcher
// ServiceUser - optional username used for this service to register in keystone
// ServiceUser - optional username used for this service to register in
// keystone
ServiceUser string `json:"serviceUser"`

// +kubebuilder:validation:Optional
Expand Down
5 changes: 5 additions & 0 deletions api/v1beta1/watcher_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ type WatcherSpec struct {
// Important: Run "make" to regenerate code after modifying this file

WatcherTemplate `json:",inline"`

// +kubebuilder:validation:Optional
// +kubebuilder:default=memcached
// MemcachedInstance is the name of the Memcached CR that all watcher service will use.
MemcachedInstance string `json:"memcachedInstance"`
}

// WatcherStatus defines the observed state of Watcher
Expand Down
5 changes: 5 additions & 0 deletions api/v1beta1/watcherapi_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@ type WatcherAPISpec struct {
// Important: Run "make" to regenerate code after modifying this file

WatcherCommon `json:",inline"`

// +kubebuilder:validation:Required
// Secret containing all passwords / keys needed
Secret string `json:"secret"`

// +kubebuilder:validation:Required
// MemcachedInstance is the name of the Memcached CR that all watcher service will use.
MemcachedInstance string `json:"memcachedInstance"`
}

// WatcherAPIStatus defines the observed state of WatcherAPI
Expand Down
11 changes: 9 additions & 2 deletions config/crd/bases/watcher.openstack.org_watcherapis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ spec:
MariaDB instance name
Required to use the mariadb-operator instance to create the DB and user
type: string
memcachedInstance:
description: MemcachedInstance is the name of the Memcached CR that
all watcher service will use.
type: string
passwordSelectors:
default:
service: WatcherPassword
Expand All @@ -66,11 +70,14 @@ spec:
type: string
serviceUser:
default: watcher
description: ServiceUser - optional username used for this service
to register in keystone
description: |-
ServiceUser - optional username used for this service to register in
keystone
type: string
required:
- databaseInstance
- memcachedInstance
- passwordSelectors
- secret
type: object
status:
Expand Down
11 changes: 9 additions & 2 deletions config/crd/bases/watcher.openstack.org_watchers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ spec:
MariaDB instance name
Required to use the mariadb-operator instance to create the DB and user
type: string
memcachedInstance:
default: memcached
description: MemcachedInstance is the name of the Memcached CR that
all watcher service will use.
type: string
passwordSelectors:
default:
service: WatcherPassword
Expand All @@ -73,11 +78,13 @@ spec:
type: string
serviceUser:
default: watcher
description: ServiceUser - optional username used for this service
to register in keystone
description: |-
ServiceUser - optional username used for this service to register in
keystone
type: string
required:
- databaseInstance
- passwordSelectors
- rabbitMqClusterName
type: object
status:
Expand Down
25 changes: 25 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ rules:
- patch
- update
- watch
- apiGroups:
- keystone.openstack.org
resources:
- keystoneapis
verbs:
- get
- list
- watch
- apiGroups:
- keystone.openstack.org
resources:
Expand Down Expand Up @@ -82,6 +90,23 @@ rules:
- patch
- update
- watch
- apiGroups:
- memcached.openstack.org
resources:
- memcacheds
verbs:
- get
- list
- patch
- update
- watch
- apiGroups:
- memcached.openstack.org
resources:
- memcacheds/finalizers
verbs:
- patch
- update
- apiGroups:
- rabbitmq.openstack.org
resources:
Expand Down
1 change: 1 addition & 0 deletions config/samples/watcher_v1beta1_watcherapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ metadata:
spec:
databaseInstance: "openstack"
secret: "osp-secret"
memcachedInstance: "memcached"
79 changes: 79 additions & 0 deletions controllers/watcher_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"

memcachedv1 "github.com/openstack-k8s-operators/infra-operator/apis/memcached/v1beta1"
"github.com/openstack-k8s-operators/lib-common/modules/common/condition"
"github.com/openstack-k8s-operators/lib-common/modules/common/env"
"github.com/openstack-k8s-operators/lib-common/modules/common/helper"
"github.com/openstack-k8s-operators/lib-common/modules/common/secret"
"github.com/openstack-k8s-operators/lib-common/modules/common/util"
)

Expand Down Expand Up @@ -188,3 +192,78 @@ func ensureSecret(

return hash, ctrl.Result{}, *secret, nil
}

func GenerateConfigsGeneric(
ctx context.Context, helper *helper.Helper,
instance client.Object,
envVars *map[string]env.Setter,
templateParameters map[string]interface{},
customData map[string]string,
cmLabels map[string]string,
scripts bool,
) error {

cms := []util.Template{
// Templates where the watcher config is stored
{
Name: fmt.Sprintf("%s-config-data", instance.GetName()),
Namespace: instance.GetNamespace(),
Type: util.TemplateTypeConfig,
InstanceType: instance.GetObjectKind().GroupVersionKind().Kind,
ConfigOptions: templateParameters,
CustomData: customData,
Labels: cmLabels,
},
}
if scripts {
cms = append(cms, util.Template{
Name: fmt.Sprintf("%s-scripts", instance.GetName()),
Namespace: instance.GetNamespace(),
Type: util.TemplateTypeScripts,
InstanceType: instance.GetObjectKind().GroupVersionKind().Kind,
ConfigOptions: templateParameters,
Labels: cmLabels,
})
}
return secret.EnsureSecrets(ctx, helper, instance, cms, envVars)
}

// ensureMemcached - gets the Memcached instance cell specific used for nova services cache backend
func ensureMemcached(
ctx context.Context,
helper *helper.Helper,
namespaceName string,
memcachedName string,
conditionUpdater conditionUpdater,
) (*memcachedv1.Memcached, error) {
memcached, err := memcachedv1.GetMemcachedByName(ctx, helper, memcachedName, namespaceName)
if err != nil {
if k8s_errors.IsNotFound(err) {
conditionUpdater.Set(condition.FalseCondition(
condition.MemcachedReadyCondition,
condition.RequestedReason,
condition.SeverityInfo,
condition.MemcachedReadyWaitingMessage))
return nil, fmt.Errorf("memcached %s not found", memcachedName)
}
conditionUpdater.Set(condition.FalseCondition(
condition.MemcachedReadyCondition,
condition.ErrorReason,
condition.SeverityWarning,
condition.MemcachedReadyErrorMessage,
err.Error()))
return nil, err
}

if !memcached.IsReady() {
conditionUpdater.Set(condition.FalseCondition(
condition.MemcachedReadyCondition,
condition.RequestedReason,
condition.SeverityInfo,
condition.MemcachedReadyWaitingMessage))
return nil, fmt.Errorf("memcached %s is not ready", memcachedName)
}
conditionUpdater.MarkTrue(condition.MemcachedReadyCondition, condition.MemcachedReadyMessage)

return memcached, err
}
Loading

0 comments on commit 48a6210

Please sign in to comment.