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

EVEREST-152 Fix Admin User Secret Management #9

Draft
wants to merge 22 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
24828f5
EVEREST-152 Simplify DatabaseCluster's API
recharte Jul 13, 2023
3d4aa68
EVEREST-152 autogen API manifests
recharte Jul 13, 2023
9cecec1
EVEREST-152 autogen bundle
recharte Jul 13, 2023
a65808b
EVEREST-152 migrate PXC reconciliation to new API
recharte Jul 13, 2023
b37d755
EVEREST-152 migrate PSMDB reconciliation to new API
recharte Jul 13, 2023
3d098da
EVEREST-152 migrate PG reconciliation to new API
recharte Jul 13, 2023
c4d92b0
EVEREST-152 migrate PG backups to new API
recharte Jul 13, 2023
0f44d06
EVEREST-152 migrate PSMDB backups to new API
recharte Jul 13, 2023
be58cc9
EVEREST-152 migrate PXC backups to new API
recharte Jul 13, 2023
ae75c9c
EVEREST-152 migrate PXC/PSMDB data source to new API
recharte Jul 13, 2023
cf82900
EVEREST-152 bump everest-operator version to 0.0.3
recharte Jul 13, 2023
b737733
EVEREST-152 fix validation of DatabaseCluster expose type
recharte Jul 13, 2023
e2f60b0
EVEREST-152 improve getting versions from DBEngine
recharte Jul 14, 2023
fb13d58
EVEREST-152 ignore gocognit linter for now
recharte Jul 14, 2023
c0b92ea
EVEREST-152 autogen manifests and bundle
recharte Jul 14, 2023
ad79fe3
EVEREST-152 make engine replicas optional
recharte Jul 14, 2023
2fd8773
EVEREST-152 improve fields description
recharte Jul 14, 2023
790572a
EVEREST-152 autogen manifests and bundle
recharte Jul 14, 2023
e928b7d
Upgrade PG operator to GA version (v2.2.0) (#8)
recharte Jul 17, 2023
e535b37
EVEREST-152 go mod tidy
recharte Jul 17, 2023
822a368
EVEREST-152 generalize admin user secret
recharte Jul 17, 2023
7c0d983
EVEREST-152 autogenerate manifests and bundle
recharte Jul 17, 2023
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
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.0.2
VERSION ?= 0.0.3

# 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
8 changes: 8 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,12 @@ resources:
kind: DatabaseClusterBackup
path: github.com/percona/everest-operator/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
domain: percona.com
group: everest
kind: ObjectStorage
path: github.com/percona/everest-operator/api/v1alpha1
version: v1alpha1
version: "3"
326 changes: 179 additions & 147 deletions api/v1alpha1/databasecluster_types.go

Large diffs are not rendered by default.

142 changes: 127 additions & 15 deletions api/v1alpha1/databaseengine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
package v1alpha1

import (
"sort"

goversion "github.com/hashicorp/go-version"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -26,12 +29,22 @@ const (
DBEngineStateInstalling EngineState = "installing"
// DBEngineStateInstalled represents the state of engine when underlying operator is installed.
DBEngineStateInstalled EngineState = "installed"

// DatabaseEnginePXC represents engine type for PXC clusters.
DatabaseEnginePXC EngineType = "pxc"
// DatabaseEnginePSMDB represents engine type for PSMDB clusters.
DatabaseEnginePSMDB EngineType = "psmdb"
// DatabaseEnginePostgresql represents engine type for Postgresql clusters.
DatabaseEnginePostgresql EngineType = "postgresql"

// DBEngineComponentRecommended represents recommended component status.
DBEngineComponentRecommended ComponentStatus = "recommended"
// DBEngineComponentAvailable represents available component status.
DBEngineComponentAvailable ComponentStatus = "available"
// DBEngineComponentUnavailable represents unavailable component status.
DBEngineComponentUnavailable ComponentStatus = "unavailable"
// DBEngineComponentUnsupported represents unsupported component status.
DBEngineComponentUnsupported ComponentStatus = "unsupported"
)

type (
Expand Down Expand Up @@ -61,7 +74,7 @@ type DatabaseEngineStatus struct {
//+kubebuilder:resource:shortName=dbengine;
//+kubebuilder:printcolumn:name="Type",type="string",JSONPath=".spec.type"
//+kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.status"
//+kubebuilder:printcolumn:name="Version",type="string",JSONPath=".status.version"
//+kubebuilder:printcolumn:name="Operator Version",type="string",JSONPath=".status.operatorVersion"

// DatabaseEngine is the Schema for the databaseengines API.
type DatabaseEngine struct {
Expand All @@ -83,29 +96,128 @@ type DatabaseEngineList struct {

// Versions struct represents available versions of database engine components.
type Versions struct {
Engine map[string]*Component `json:"engine,omitempty"`
Backup map[string]*Component `json:"backup,omitempty"`
Proxy map[string]map[string]*Component `json:"proxy,omitempty"`
Tools map[string]map[string]*Component `json:"tools,omitempty"`
Engine ComponentsMap `json:"engine,omitempty"`
Backup ComponentsMap `json:"backup,omitempty"`
Proxy map[ProxyType]ComponentsMap `json:"proxy,omitempty"`
Tools map[string]ComponentsMap `json:"tools,omitempty"`
}

// ComponentsMap is a map of database engine components.
type ComponentsMap map[string]*Component

// ComponentStatus represents status of the database engine component.
type ComponentStatus string

// Component contains information of the database engine component.
// Database Engine component can be database engine, database proxy or tools image path.
type Component struct {
Critical bool `json:"critical,omitempty"`
ImageHash string `json:"imageHash,omitempty"`
ImagePath string `json:"imagePath,omitempty"`
Status string `json:"status,omitempty"`
Critical bool `json:"critical,omitempty"`
ImageHash string `json:"imageHash,omitempty"`
ImagePath string `json:"imagePath,omitempty"`
Status ComponentStatus `json:"status,omitempty"`
}

// RecommendedBackupImage returns the recommended image for a backup component.
func (d DatabaseEngine) RecommendedBackupImage() string {
for _, component := range d.Status.AvailableVersions.Backup {
if component.Status == "recommended" {
return component.ImagePath
// FilterStatus returns a new ComponentsMap with components filtered by status.
func (c ComponentsMap) FilterStatus(statuses ...ComponentStatus) ComponentsMap {
result := make(ComponentsMap)
for version, component := range c {
for _, status := range statuses {
if component.Status == status {
result[version] = component
}
}
}
return result
}

// GetSortedVersions returns a sorted slice of versions. Versions are sorted in
// descending order. Most recent version is first.
func (c ComponentsMap) GetSortedVersions() []string {
versions := make(goversion.Collection, 0, len(c))
for version := range c {
v, err := goversion.NewVersion(version)
if err != nil {
continue
}
versions = append(versions, v)
}
sort.Sort(versions)

// Reverse order and return the original version strings.
result := make([]string, 0, len(versions))
for i := len(versions) - 1; i >= 0; i-- {
result = append(result, versions[i].Original())
}

return result
}

// GetAllowedVersionsSorted returns a sorted slice of allowed versions.
// An allowed version is a version whose status is either recommended or
// available. Allowed versions are sorted by status, with recommended versions
// first, followed by available versions. Versions with the same status are
// sorted by version in descending order. Most recent version is first.
func (c ComponentsMap) GetAllowedVersionsSorted() []string {
recommendedComponents := c.FilterStatus(DBEngineComponentRecommended)
recommendedVersions := recommendedComponents.GetSortedVersions()

availableComponents := c.FilterStatus(DBEngineComponentAvailable)
availableVersions := availableComponents.GetSortedVersions()

return append(recommendedVersions, availableVersions...)
}

// BestVersion returns the best version for the components map.
func (c ComponentsMap) BestVersion() string {
allowedVersions := c.GetAllowedVersionsSorted()
return allowedVersions[0]
}

// BestEngineVersion returns the best engine version for the database engine.
func (d DatabaseEngine) BestEngineVersion() string {
return d.Status.AvailableVersions.Engine.BestVersion()
}

// BestBackupVersion returns the best backup version for a given engine version.
func (d DatabaseEngine) BestBackupVersion(engineVersion string) string {
switch d.Spec.Type {
case DatabaseEnginePXC:
engineGoVersion, err := goversion.NewVersion(engineVersion)
if err != nil {
return ""
}

v8, err := goversion.NewVersion("8.0.0")
if err != nil {
return ""
}

engineIsV8 := engineGoVersion.GreaterThanOrEqual(v8)
allowedVersions := d.Status.AvailableVersions.Backup.GetAllowedVersionsSorted()
for _, version := range allowedVersions {
v, err := goversion.NewVersion(version)
if err != nil {
continue
}
if !engineIsV8 && v.GreaterThanOrEqual(v8) {
continue
}
if engineIsV8 && v.LessThan(v8) {
continue
}
return version
}
return ""
case DatabaseEnginePSMDB:
return d.Status.AvailableVersions.Backup.BestVersion()
case DatabaseEnginePostgresql:
if d.Status.AvailableVersions.Backup[engineVersion] == nil {
return ""
}
return engineVersion
default:
return ""
}
return ""
}

func init() {
Expand Down
71 changes: 71 additions & 0 deletions api/v1alpha1/objectstorage_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// everest-operator
// Copyright (C) 2022 Percona LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const (
// ObjectStorageTypeS3 is a type of S3 object storage.
ObjectStorageTypeS3 ObjectStorageType = "s3"
)

// ObjectStorageType is a type of object storage.
type ObjectStorageType string

// ObjectStorageSpec defines the desired state of ObjectStorage.
type ObjectStorageSpec struct {
// Type is a type of object storage. Currently only S3 is supported.
// +kubebuilder:validation:Enum=s3
Type ObjectStorageType `json:"type"`
// Bucket is a name of bucket.
Bucket string `json:"bucket"`
// Region is a region where the bucket is located.
Region string `json:"region"`
// EndpointURL is an endpoint URL of object storage.
EndpointURL string `json:"endpointURL"`
// CredentialsSecretName is the name of the secret with credentials.
CredentialsSecretName string `json:"credentialsSecretName"`
}

// ObjectStorageStatus defines the observed state of ObjectStorage.
type ObjectStorageStatus struct{}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

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

Spec ObjectStorageSpec `json:"spec,omitempty"`
Status ObjectStorageStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&ObjectStorage{}, &ObjectStorageList{})
}
Loading