Skip to content

Commit

Permalink
EVEREST-496 Multi namespace support (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
gen1us2k authored Nov 23, 2023
1 parent 94b4c08 commit 6e8aea6
Show file tree
Hide file tree
Showing 69 changed files with 2,137 additions and 111 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# To re-generate a bundle for another specific version without changing the standard setup, you can:
# - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2)
# - use environment variables to overwrite this value (e.g export VERSION=0.0.2)
VERSION ?= 0.5.0-dev2
VERSION ?= 0.6.0-dev1

# CHANNELS define the bundle channels used in the bundle.
# Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable")
Expand Down
2 changes: 2 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ resources:
- api:
crdVersion: v1
namespaced: true
controller: true
domain: percona.com
group: everest
kind: BackupStorage
Expand All @@ -58,6 +59,7 @@ resources:
- api:
crdVersion: v1
namespaced: true
controller: true
domain: percona.com
group: everest
kind: MonitoringConfig
Expand Down
44 changes: 43 additions & 1 deletion api/v1alpha1/backupstorage_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,14 @@ type BackupStorageSpec struct {
Description string `json:"description,omitempty"`
// CredentialsSecretName is the name of the secret with credentials.
CredentialsSecretName string `json:"credentialsSecretName"`
// TargetNamespaces is the list of namespaces where the operator will copy secrets provided in the CredentialsSecretsName.
TargetNamespaces []string `json:"targetNamespaces,omitempty"`
}

// BackupStorageStatus defines the observed state of BackupStorage.
type BackupStorageStatus struct{}
type BackupStorageStatus struct {
UsedNamespaces map[string]bool `json:"usedNamespaces"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
Expand All @@ -74,3 +78,41 @@ type BackupStorageList struct {
func init() {
SchemeBuilder.Register(&BackupStorage{}, &BackupStorageList{})
}

// UpdateNamespacesList updates the list of namespaces that use the backupStorage.
func (b *BackupStorage) UpdateNamespacesList(namespace string) bool {
if b.Status.UsedNamespaces == nil {
b.Status.UsedNamespaces = make(map[string]bool)
}
if _, ok := b.Status.UsedNamespaces[namespace]; ok {
return false
}
b.Status.UsedNamespaces[namespace] = true
return true
}

// DeleteUsedNamespace deletes the namespace from the usedNamespaces list.
func (b *BackupStorage) DeleteUsedNamespace(namespace string) bool {
if b.Status.UsedNamespaces == nil {
return false
}
if _, ok := b.Status.UsedNamespaces[namespace]; ok {
delete(b.Status.UsedNamespaces, namespace)
return true
}
return false
}

// IsNamespaceAllowed checks the namespace against targetNamespaces and returns if it's allowed to use.
func (b *BackupStorage) IsNamespaceAllowed(namespace string) bool {
if len(b.Spec.TargetNamespaces) == 0 {
return true
}
for _, ns := range b.Spec.TargetNamespaces {
ns := ns
if ns == namespace {
return true
}
}
return false
}
44 changes: 43 additions & 1 deletion api/v1alpha1/monitoringconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ type MonitoringConfigSpec struct {
Type MonitoringType `json:"type"`
// CredentialsSecretName is the name of the secret with credentials.
CredentialsSecretName string `json:"credentialsSecretName"`
// TargetNamespaces is the list of namespaces where the operator will copy secrets provided in the CredentialsSecretsName.
TargetNamespaces []string `json:"targetNamespaces,omitempty"`
// PMM is configuration for the PMM monitoring type.
PMM PMMConfig `json:"pmm,omitempty"`
}
Expand All @@ -47,7 +49,9 @@ type PMMConfig struct {
}

// MonitoringConfigStatus defines the observed state of MonitoringConfig.
type MonitoringConfigStatus struct{}
type MonitoringConfigStatus struct {
UsedNamespaces map[string]bool `json:"usedNamespaces"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
Expand All @@ -74,3 +78,41 @@ type MonitoringConfigList struct {
func init() {
SchemeBuilder.Register(&MonitoringConfig{}, &MonitoringConfigList{})
}

// UpdateNamespacesList updates the list of namespaces that use the monitoring config.
func (m *MonitoringConfig) UpdateNamespacesList(namespace string) bool {
if m.Status.UsedNamespaces == nil {
m.Status.UsedNamespaces = make(map[string]bool)
}
if _, ok := m.Status.UsedNamespaces[namespace]; ok {
return false
}
m.Status.UsedNamespaces[namespace] = true
return true
}

// DeleteUsedNamespace deletes the namespace from the usedNamespaces list.
func (m *MonitoringConfig) DeleteUsedNamespace(namespace string) bool {
if m.Status.UsedNamespaces == nil {
return false
}
if _, ok := m.Status.UsedNamespaces[namespace]; ok {
delete(m.Status.UsedNamespaces, namespace)
return true
}
return false
}

// IsNamespaceAllowed checks the namespace against targetNamespaces and returns if it's allowed to use.
func (m *MonitoringConfig) IsNamespaceAllowed(namespace string) bool {
if len(m.Spec.TargetNamespaces) == 0 {
return true
}
for _, ns := range m.Spec.TargetNamespaces {
ns := ns
if ns == namespace {
return true
}
}
return false
}
32 changes: 28 additions & 4 deletions api/v1alpha1/zz_generated.deepcopy.go

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

44 changes: 36 additions & 8 deletions bundle/manifests/everest-operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ metadata:
}
]
capabilities: Basic Install
createdAt: "2023-11-22T14:28:14Z"
createdAt: "2023-11-23T12:27:38Z"
operators.operatorframework.io/builder: operator-sdk-v1.32.0
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
name: everest-operator.v0.5.0-dev2
name: everest-operator.v0.6.0-dev1
namespace: placeholder
spec:
apiservicedefinitions: {}
Expand Down Expand Up @@ -193,6 +193,20 @@ spec:
- patch
- update
- watch
- apiGroups:
- everest.percona.com
resources:
- backupstorages/finalizers
verbs:
- update
- apiGroups:
- everest.percona.com
resources:
- backupstorages/status
verbs:
- get
- patch
- update
- apiGroups:
- everest.percona.com
resources:
Expand Down Expand Up @@ -309,6 +323,20 @@ spec:
- patch
- update
- watch
- apiGroups:
- everest.percona.com
resources:
- monitoringconfigs/finalizers
verbs:
- update
- apiGroups:
- everest.percona.com
resources:
- monitoringconfigs/status
verbs:
- get
- patch
- update
- apiGroups:
- pgv2.percona.com
resources:
Expand Down Expand Up @@ -512,11 +540,11 @@ spec:
command:
- /manager
env:
- name: WATCH_NAMESPACE
- name: DEFAULT_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.annotations['olm.targetNamespaces']
image: docker.io/perconalab/everest-operator:0.5.0-dev2
fieldPath: metadata.namespace
image: docker.io/perconalab/everest-operator:0.6.0-dev1
livenessProbe:
httpGet:
path: /healthz
Expand Down Expand Up @@ -586,9 +614,9 @@ spec:
type: OwnNamespace
- supported: true
type: SingleNamespace
- supported: false
type: MultiNamespace
- supported: true
type: MultiNamespace
- supported: false
type: AllNamespaces
keywords:
- everest
Expand All @@ -610,4 +638,4 @@ spec:
provider:
name: Percona
url: https://percona.com
version: 0.5.0-dev2
version: 0.6.0-dev1
13 changes: 13 additions & 0 deletions bundle/manifests/everest.percona.com_backupstorages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ spec:
region:
description: Region is a region where the bucket is located.
type: string
targetNamespaces:
description: TargetNamespaces is the list of namespaces where the
operator will copy secrets provided in the CredentialsSecretsName.
items:
type: string
type: array
type:
description: Type is a type of backup storage.
enum:
Expand All @@ -63,6 +69,13 @@ spec:
type: object
status:
description: BackupStorageStatus defines the observed state of BackupStorage.
properties:
usedNamespaces:
additionalProperties:
type: boolean
type: object
required:
- usedNamespaces
type: object
type: object
served: true
Expand Down
13 changes: 13 additions & 0 deletions bundle/manifests/everest.percona.com_monitoringconfigs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ spec:
- image
- url
type: object
targetNamespaces:
description: TargetNamespaces is the list of namespaces where the
operator will copy secrets provided in the CredentialsSecretsName.
items:
type: string
type: array
type:
description: Type is type of monitoring.
enum:
Expand All @@ -68,6 +74,13 @@ spec:
type: object
status:
description: MonitoringConfigStatus defines the observed state of MonitoringConfig.
properties:
usedNamespaces:
additionalProperties:
type: boolean
type: object
required:
- usedNamespaces
type: object
type: object
served: true
Expand Down
13 changes: 13 additions & 0 deletions config/crd/bases/everest.percona.com_backupstorages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ spec:
region:
description: Region is a region where the bucket is located.
type: string
targetNamespaces:
description: TargetNamespaces is the list of namespaces where the
operator will copy secrets provided in the CredentialsSecretsName.
items:
type: string
type: array
type:
description: Type is a type of backup storage.
enum:
Expand All @@ -64,6 +70,13 @@ spec:
type: object
status:
description: BackupStorageStatus defines the observed state of BackupStorage.
properties:
usedNamespaces:
additionalProperties:
type: boolean
type: object
required:
- usedNamespaces
type: object
type: object
served: true
Expand Down
Loading

0 comments on commit 6e8aea6

Please sign in to comment.