Skip to content

Commit

Permalink
feat: add options struct and prune client (#20)
Browse files Browse the repository at this point in the history
whg517 authored May 23, 2024
1 parent d18b933 commit 74e4b13
Showing 35 changed files with 1,201 additions and 836 deletions.
55 changes: 51 additions & 4 deletions api/v1alpha1/clusterconfig_types.go
Original file line number Diff line number Diff line change
@@ -7,10 +7,57 @@ type ClusterConfigSpec struct {
// +kubebuilder:validation:Required
Redis *RedisSpec `json:"redis"`

// +kubebuilder:validation:Required
Administrator *AdministratorSpec `json:"administrator"`

// +kubebuilder:validation:Optional
// This is flask app secret key
AppSecretKey *AppSecretKeySpec `json:"appSecretKey,omitempty"`

// +kubebuilder:validation:Optional
ListenerClass string `json:"listenerClass,omitempty"`
}

// AppSecretKeySpec defines the app secret key spec.
type AppSecretKeySpec struct {
// +kubebuilder:validation=Optional
// ExistSecret is the name of the secret that contains the secret key.
// It must contain the key `SUPERSET_SECRET_KEY`.
// Note: To avoid the key name confusions, the key name must be started with `SUPERSET_`.
ExistSecret string `json:"existSecret,omitempty"`
// +kubebuilder:validation=Optional
// If value is not set, the secret will be generated.
// When you migrate the Superset instance, you should keep the same secret key in the new instance.
SecretKey string `json:"secretKey,omitempty"`
}

type AdministratorSpec struct {
// +kubebuilder:validation=Optional
// +kubebuilder:default="admin"
Username string `json:"username,omitempty"`
// +kubebuilder:validation=Optional
// +kubebuilder:default="Superset"
FirstName string `json:"firstName,omitempty"`
// +kubebuilder:validation=Optional
// +kubebuilder:default="Admin"
LastName string `json:"lastName,omitempty"`
// +kubebuilder:validation=Optional
// +kubebuilder:default="admin@superset"
Email string `json:"email,omitempty"`
// +kubebuilder:validation=Optional
// +kubebuilder:default="admin"
Password string `json:"password,omitempty"`
// +kubebuilder:validation=Optional
// ExistSecret is the name of the secret that contains the administrator info.
// It must contain the following keys:
// - `ADMIN_USERNAME`
// - `ADMIN_FIRST_NAME`
// - `ADMIN_LAST_NAME`
// - `ADMIN_EMAIL`
// - `ADMIN_PASSWORD`
ExistSecret string `json:"existSecret,omitempty"`
}

// RedisSpec defines the redis spec.
type RedisSpec struct {
// +kubebuilder:validation=Optional
@@ -37,7 +84,7 @@ type RedisSpec struct {

type DatabaseSpec struct {
// +kubebuilder:validation=Optional
Reference string `json:"reference"`
Reference *string `json:"reference,omitempty"`

// +kubebuilder:validation=Optional
Inline *DatabaseInlineSpec `json:"inline,omitempty"`
@@ -50,15 +97,15 @@ type DatabaseInlineSpec struct {
Driver string `json:"driver,omitempty"`

// +kubebuilder:validation=Optional
// +kubebuilder:default="hive"
// +kubebuilder:default="superset"
DatabaseName string `json:"databaseName,omitempty"`

// +kubebuilder:validation=Optional
// +kubebuilder:default="hive"
// +kubebuilder:default="superset"
Username string `json:"username,omitempty"`

// +kubebuilder:validation=Optional
// +kubebuilder:default="hive"
// +kubebuilder:default="superset"
Password string `json:"password,omitempty"`

// +kubebuilder:validation=Required
10 changes: 7 additions & 3 deletions api/v1alpha1/image_types.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package v1alpha1

type ImageSpec struct {
Custom string `json:"custom,omitempty"`
Repo string `json:"repo,omitempty"`
KDSVersion string `json:"kdsVersion,omitempty"`
// +kubebuilder:validation:Optional
Custom string `json:"custom,omitempty"`
// +kubebuilder:validation:Optional
Repo string `json:"repo,omitempty"`
// +kubebuilder:validation:Optional
KDSVersion string `json:"kdsVersion,omitempty"`
// +kubebuilder:validation:Optional
ProductVersion string `json:"productVersion,omitempty"`
}
2 changes: 1 addition & 1 deletion api/v1alpha1/supersetcluster_types.go
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ import (
type SupersetClusterSpec struct {
Image *ImageSpec `json:"image,omitempty"`
ClusterConfig *ClusterConfigSpec `json:"clusterConfig"`
ClusterOperation *apiv1alpha1.ClusterOperationSpec `json:"clusterOperation"`
ClusterOperation *apiv1alpha1.ClusterOperationSpec `json:"clusterOperation,omitempty"`
Node *NodeSpec `json:"node"`
Worker *WorkerSpec `json:"worker"`
}
45 changes: 45 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

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

16 changes: 5 additions & 11 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -18,7 +18,6 @@ package main

import (
"flag"
"fmt"
"os"
"strings"

@@ -66,12 +65,6 @@ func main() {

ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))

watchNamespaces, err := getWatchNamespaces()
if err != nil {
setupLog.Error(err, "unable to get watch namespaces")
os.Exit(1)
}

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
Metrics: server.Options{BindAddress: metricsAddr},
@@ -89,7 +82,7 @@ func main() {
// if you are doing or is intended to do any operation such as perform cleanups
// after the manager stops then its usage might be unsafe.
// LeaderElectionReleaseOnCancel: true,
Cache: cache.Options{DefaultNamespaces: watchNamespaces},
Cache: cache.Options{DefaultNamespaces: getWatchNamespaces()},
})
if err != nil {
setupLog.Error(err, "unable to start manager")
@@ -122,15 +115,16 @@ func main() {
}

// getWatchNamespaces returns the Namespaces the operator should be watching for changes
func getWatchNamespaces() (map[string]cache.Config, error) {
func getWatchNamespaces() map[string]cache.Config {
// WatchNamespacesEnvVar is the constant for env variable WATCH_NAMESPACES
// which specifies the Namespaces to watch.
// An empty value means the operator is running with cluster scope.
var watchNamespacesEnvVar = "WATCH_NAMESPACES"

ns, found := os.LookupEnv(watchNamespacesEnvVar)
if !found {
return nil, fmt.Errorf("%s must be set", watchNamespacesEnvVar)
setupLog.Info("watchNamespaces", "namespaces", "all")
return nil
}
nss := cleanNamespaceList(ns)

@@ -146,7 +140,7 @@ func getWatchNamespaces() (map[string]cache.Config, error) {
setupLog.Info("watchNamespaces", "namespaces", "all")
}

return cachedNamespaces, nil
return cachedNamespaces
}

func cleanNamespaceList(namespaces string) (result []string) {
49 changes: 43 additions & 6 deletions config/crd/bases/superset.zncdata.dev_supersetclusters.yaml
Original file line number Diff line number Diff line change
@@ -36,14 +36,53 @@ spec:
properties:
clusterConfig:
properties:
administrator:
properties:
email:
default: admin@superset
type: string
existSecret:
description: 'ExistSecret is the name of the secret that contains
the administrator info. It must contain the following keys:
- `ADMIN_USERNAME` - `ADMIN_FIRST_NAME` - `ADMIN_LAST_NAME`
- `ADMIN_EMAIL` - `ADMIN_PASSWORD`'
type: string
firstName:
default: Superset
type: string
lastName:
default: Admin
type: string
password:
default: admin
type: string
username:
default: admin
type: string
type: object
appSecretKey:
description: This is flask app secret key
properties:
existSecret:
description: 'ExistSecret is the name of the secret that contains
the secret key. It must contain the key `SUPERSET_SECRET_KEY`.
Note: To avoid the key name confusions, the key name must
be started with `SUPERSET_`.'
type: string
secretKey:
description: If value is not set, the secret will be generated.
When you migrate the Superset instance, you should keep
the same secret key in the new instance.
type: string
type: object
database:
properties:
inline:
description: DatabaseInlineSpec defines the inline database
spec.
properties:
databaseName:
default: hive
default: superset
type: string
driver:
default: postgres
@@ -54,20 +93,18 @@ spec:
host:
type: string
password:
default: hive
default: superset
type: string
port:
default: 5432
format: int32
type: integer
username:
default: hive
default: superset
type: string
type: object
reference:
type: string
required:
- reference
type: object
listenerClass:
type: string
@@ -101,6 +138,7 @@ spec:
- host
type: object
required:
- administrator
- database
- redis
type: object
@@ -5403,7 +5441,6 @@ spec:
type: object
required:
- clusterConfig
- clusterOperation
- node
- worker
type: object
24 changes: 23 additions & 1 deletion config/samples/superset_v1alpha1_supersetcluster.yaml
Original file line number Diff line number Diff line change
@@ -9,4 +9,26 @@ metadata:
app.kubernetes.io/created-by: superset-operator
name: supersetcluster-sample
spec:
# TODO(user): Add fields here
image:
custom: apache/superset:4.0.1
clusterConfig:
database:
inline:
driver: postgres
databaseName: superset
username: superset
password: superset
host: 192.168.205.1
redis:
host: 192.168.205.1
administrator:
username: admin
password: admin
node:
roleGroups:
default:
replicas: 1
worker:
roleGroups:
default:
replicas: 1
Loading

0 comments on commit 74e4b13

Please sign in to comment.