mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 14:37:34 +00:00
fix: operator picks (#1463)
* feat(crd): add crd mode for operators (#1329) * feat(operator): add base for zitadel operator * fix(operator): changed pipeline to release operator * fix(operator): fmt with only one parameter * fix(operator): corrected workflow job name * fix(zitadelctl): added restore and backuplist command * fix(zitadelctl): scale for restore * chore(container): use scratch for deploy container * fix(zitadelctl): limit image to scratch * fix(migration): added migration scripts for newer version * fix(operator): changed handling of kubeconfig in operator logic * fix(operator): changed handling of secrets in operator logic * fix(operator): use new version of zitadel * fix(operator): added path for migrations * fix(operator): delete doublets of migration scripts * fix(operator): delete subpaths and integrate logic into init container * fix(operator): corrected path in dockerfile for local migrations * fix(operator): added migrations for cockroachdb-secure * fix(operator): delete logic for ambassador module * fix(operator): added read and write secret commands * fix(operator): correct and align operator pipeline with zitadel pipeline * fix(operator): correct yaml error in operator pipeline * fix(operator): correct action name in operator pipeline * fix(operator): correct case-sensitive filename in operator pipeline * fix(operator): upload artifacts from buildx output * fix(operator): corrected attribute spelling error * fix(operator): combined jobs for operator binary and image * fix(operator): added missing comma in operator pipeline * fix(operator): added codecov for operator image * fix(operator): added codecov for operator image * fix(testing): code changes for testing and several unit-tests (#1009) * fix(operator): usage of interface of kubernetes client for testing and several unit-tests * fix(operator): several unit-tests * fix(operator): several unit-tests * fix(operator): changed order for the operator logic * fix(operator): added version of zitadelctl from semantic release * fix(operator): corrected function call with version of zitadelctl * fix(operator): corrected function call with version of zitadelctl * fix(operator): add check output to operator release pipeline * fix(operator): set --short length everywhere to 12 * fix(operator): zitadel setup in job instead of exec with several unit tests * fix(operator): fixes to combine newest zitadel and testing branch * fix(operator): corrected path in Dockerfile * fix(operator): fixed unit-test that was ignored during changes * fix(operator): fixed unit-test that was ignored during changes * fix(operator): corrected Dockerfile to correctly use env variable * fix(operator): quickfix takeoff deployment * fix(operator): corrected the clusterrolename in the applied artifacts * fix: update secure migrations * fix(operator): migrations (#1057) * fix(operator): copied migrations from orbos repository * fix(operator): newest migrations * chore: use cockroach-secure * fix: rename migration * fix: remove insecure cockroach migrations Co-authored-by: Stefan Benz <stefan@caos.ch> * fix: finalize labels * fix(operator): cli logging concurrent and fixe deployment of operator during restore * fix: finalize labels and cli commands * fix: restore * chore: cockroachdb is always secure * chore: use orbos consistent-labels latest commit * test: make tests compatible with new labels * fix: default to sa token for start command * fix: use cockroachdb v12.02 * fix: don't delete flyway user * test: fix migration test * fix: use correct table qualifiers * fix: don't alter sequence ownership * fix: upgrade flyway * fix: change ownership of all dbs and tables to admin user * fix: change defaultdb user * fix: treat clientid status codes >= 400 as errors * fix: reconcile specified ZITADEL version, not binary version * fix: add ca-certs * fix: use latest orbos code * fix: use orbos with fixed race condition * fix: use latest ORBOS code * fix: use latest ORBOS code * fix: make migration and scaling around restoring work * fix(operator): move zitadel operator * chore(migrations): include owner change migration * feat(db): add code base for database operator * fix(db): change used image registry for database operator * fix(db): generated mock * fix(db): add accidentally ignored file * fix(db): add cockroachdb backup image to pipeline * fix(db): correct pipeline and image versions * fix(db): correct version of used orbos * fix(db): correct database import * fix(db): go mod tidy * fix(db): use new version for orbos * fix(migrations): include migrations into zitadelctl binary (#1211) * fix(db): use statik to integrate migrations into binary * fix(migrations): corrections unit tests and pipeline for integrated migrations into zitadelctl binary * fix(migrations): correction in dockerfile for pipeline build * fix(migrations): correction in dockerfile for pipeline build * fix(migrations): dockerfile changes for cache optimization * fix(database): correct used part-of label in database operator * fix(database): correct used selectable label in zitadel operator * fix(operator): correct lables for user secrets in zitadel operator * fix(operator): correct lables for service test in zitadel operator * fix: don't enable database features for user operations (#1227) * fix: don't enable database features for user operations * fix: omit database feature for connection info adapter * fix: use latest orbos version * fix(crd): corrected logic to get database connection and other info * fix(crd): corrected yaml tags and start for zitadel operator * fix(crd): move some dependencies and use consistent structure * fix(crd): corrected unit-tests * fix(crd): corrected main files for debug starts * chore(pipeline): use correct version for zitadelctl build * fix(crd): correct calculating of current db state for zitadel operator * fix(crd): use binary version for deployment of crd mode operators * fix(crd): add gitops attribute for reconciling * fix(crd): corrected crd with newest version * fix(migration): collect cleanup functions and only use them if all jobs are successful * fix(zitadelctl): import gcp auth to connect to gke cluster * feat: Add read and writesecret options for crd mode (#1435) * fix: don't require orbconfig for crd mode * test: pass * fix(zitadelctl): import gcp auth to connect to gke cluster * feat: add read and writesecret option for crd mode * test: fix * fix: make all crd secrets writable * fix: use in-cluster configs for in-cluster operators * chore: remove unnecessary debug files Co-authored-by: Stefan Benz <stefan@caos.ch> * fix: Crdoperatormerge review (#1385) * fix: don't require orbconfig for crd mode * test: pass * fix(zitadelctl): import gcp auth to connect to gke cluster * fix: ensure caos-system namespace * fix: apply orbconfig at takeoff * docs: improve help for creating an orbconfig * docs: describe orbconfig properties * docs: add --gitops to help message example * fix(pipeline): correct upload of artifacts in dev releases * test: pass Co-authored-by: Stefan Benz <stefan@caos.ch> * fix(test): corrected falsely merged tests * chore: update orbos library * fix: only handle exactly named and namespaced crd resource * fix: print errors, check correct crd namespace * fix: validate bucket secret * chore: compile * fix(operator): corrected secret handling when unused secrets are not defined * fix(operator): corrected handling of jobs * fix: dont print logs when readsecret path is provided * fix(operator): corrected handling of jobs and sort for mounted volumes * fix(operator): sort for volumes * fix(operator): change orboos import to newest release Co-authored-by: Florian Forster <florian@caos.ch> Co-authored-by: Elio Bischof <eliobischof@gmail.com> (cherry picked from commitfa9bd5a8e7
) * fix(operator): Standard timeout handling (#1458) * fix: always use standard time.Duration * fix: give backup and restore more time * fix: give backup and restore jobs more time (cherry picked from commit7468b7d1e8
) * fix go mod Co-authored-by: Stefan Benz <46600784+stebenz@users.noreply.github.com> Co-authored-by: Elio Bischof <eliobischof@gmail.com>
This commit is contained in:
@@ -22,7 +22,7 @@ func InstantBackup(
|
||||
}
|
||||
current := &tree.Tree{}
|
||||
|
||||
query, _, _, err := orbdb.AdaptFunc(name, nil, "instantbackup")(monitor, desired, current)
|
||||
query, _, _, _, _, err := orbdb.AdaptFunc(name, nil, false, "instantbackup")(monitor, desired, current)
|
||||
if err != nil {
|
||||
monitor.Error(err)
|
||||
return err
|
||||
|
@@ -23,7 +23,7 @@ func Clear(
|
||||
}
|
||||
current := &tree.Tree{}
|
||||
|
||||
query, _, _, err := orbdb.AdaptFunc("", nil, "clean")(monitor, desired, current)
|
||||
query, _, _, _, _, err := orbdb.AdaptFunc("", nil, false, "clean")(monitor, desired, current)
|
||||
if err != nil {
|
||||
monitor.Error(err)
|
||||
return err
|
||||
|
@@ -6,11 +6,24 @@ import (
|
||||
"github.com/caos/orbos/pkg/kubernetes"
|
||||
"github.com/caos/orbos/pkg/tree"
|
||||
"github.com/caos/zitadel/operator/api"
|
||||
"github.com/caos/zitadel/operator/api/database"
|
||||
coredb "github.com/caos/zitadel/operator/database/kinds/databases/core"
|
||||
orbdb "github.com/caos/zitadel/operator/database/kinds/orb"
|
||||
)
|
||||
|
||||
func GetConnectionInfo(
|
||||
func CrdGetConnectionInfo(
|
||||
monitor mntr.Monitor,
|
||||
k8sClient kubernetes.ClientInt,
|
||||
) (string, string, error) {
|
||||
desired, err := database.ReadCrd(k8sClient)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
return getConnectionInfo(monitor, k8sClient, desired)
|
||||
}
|
||||
|
||||
func GitOpsGetConnectionInfo(
|
||||
monitor mntr.Monitor,
|
||||
k8sClient kubernetes.ClientInt,
|
||||
gitClient *git.Client,
|
||||
@@ -20,9 +33,18 @@ func GetConnectionInfo(
|
||||
monitor.Error(err)
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
return getConnectionInfo(monitor, k8sClient, desired)
|
||||
}
|
||||
|
||||
func getConnectionInfo(
|
||||
monitor mntr.Monitor,
|
||||
k8sClient kubernetes.ClientInt,
|
||||
desired *tree.Tree,
|
||||
) (string, string, error) {
|
||||
current := &tree.Tree{}
|
||||
|
||||
query, _, _, err := orbdb.AdaptFunc("", nil)(monitor, desired, current)
|
||||
query, _, _, _, _, err := orbdb.AdaptFunc("", nil, false, "database")(monitor, desired, current)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
|
@@ -24,7 +24,7 @@ func Restore(
|
||||
}
|
||||
current := &tree.Tree{}
|
||||
|
||||
query, _, _, err := orbdb.AdaptFunc(name, nil, "restore")(monitor, desired, current)
|
||||
query, _, _, _, _, err := orbdb.AdaptFunc(name, nil, false, "restore")(monitor, desired, current)
|
||||
if err != nil {
|
||||
monitor.Error(err)
|
||||
return err
|
||||
|
@@ -6,11 +6,25 @@ import (
|
||||
"github.com/caos/orbos/pkg/kubernetes"
|
||||
"github.com/caos/orbos/pkg/tree"
|
||||
"github.com/caos/zitadel/operator/api"
|
||||
"github.com/caos/zitadel/operator/api/database"
|
||||
coredb "github.com/caos/zitadel/operator/database/kinds/databases/core"
|
||||
orbdb "github.com/caos/zitadel/operator/database/kinds/orb"
|
||||
)
|
||||
|
||||
func ListUsers(
|
||||
func CrdListUsers(
|
||||
monitor mntr.Monitor,
|
||||
k8sClient kubernetes.ClientInt,
|
||||
) ([]string, error) {
|
||||
desired, err := database.ReadCrd(k8sClient)
|
||||
if err != nil {
|
||||
monitor.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return listUsers(monitor, k8sClient, desired)
|
||||
}
|
||||
|
||||
func GitOpsListUsers(
|
||||
monitor mntr.Monitor,
|
||||
k8sClient kubernetes.ClientInt,
|
||||
gitClient *git.Client,
|
||||
@@ -20,9 +34,18 @@ func ListUsers(
|
||||
monitor.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return listUsers(monitor, k8sClient, desired)
|
||||
}
|
||||
|
||||
func listUsers(
|
||||
monitor mntr.Monitor,
|
||||
k8sClient kubernetes.ClientInt,
|
||||
desired *tree.Tree,
|
||||
) ([]string, error) {
|
||||
current := &tree.Tree{}
|
||||
|
||||
query, _, _, err := orbdb.AdaptFunc("", nil)(monitor, desired, current)
|
||||
query, _, _, _, _, err := orbdb.AdaptFunc("", nil, false, "database")(monitor, desired, current)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -52,7 +75,20 @@ func ListUsers(
|
||||
return users, nil
|
||||
}
|
||||
|
||||
func AddUser(
|
||||
func CrdAddUser(
|
||||
monitor mntr.Monitor,
|
||||
user string,
|
||||
k8sClient kubernetes.ClientInt,
|
||||
) error {
|
||||
desired, err := database.ReadCrd(k8sClient)
|
||||
if err != nil {
|
||||
monitor.Error(err)
|
||||
return err
|
||||
}
|
||||
return addUser(monitor, user, k8sClient, desired)
|
||||
}
|
||||
|
||||
func GitOpsAddUser(
|
||||
monitor mntr.Monitor,
|
||||
user string,
|
||||
k8sClient kubernetes.ClientInt,
|
||||
@@ -63,9 +99,18 @@ func AddUser(
|
||||
monitor.Error(err)
|
||||
return err
|
||||
}
|
||||
return addUser(monitor, user, k8sClient, desired)
|
||||
}
|
||||
|
||||
func addUser(
|
||||
monitor mntr.Monitor,
|
||||
user string,
|
||||
k8sClient kubernetes.ClientInt,
|
||||
desired *tree.Tree,
|
||||
) error {
|
||||
current := &tree.Tree{}
|
||||
|
||||
query, _, _, err := orbdb.AdaptFunc("", nil)(monitor, desired, current)
|
||||
query, _, _, _, _, err := orbdb.AdaptFunc("", nil, false, "database")(monitor, desired, current)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -91,7 +136,7 @@ func AddUser(
|
||||
return ensureUser(k8sClient)
|
||||
}
|
||||
|
||||
func DeleteUser(
|
||||
func GitOpsDeleteUser(
|
||||
monitor mntr.Monitor,
|
||||
user string,
|
||||
k8sClient kubernetes.ClientInt,
|
||||
@@ -102,9 +147,33 @@ func DeleteUser(
|
||||
monitor.Error(err)
|
||||
return err
|
||||
}
|
||||
|
||||
return deleteUser(monitor, user, k8sClient, desired)
|
||||
}
|
||||
|
||||
func CrdDeleteUser(
|
||||
monitor mntr.Monitor,
|
||||
user string,
|
||||
k8sClient kubernetes.ClientInt,
|
||||
) error {
|
||||
desired, err := database.ReadCrd(k8sClient)
|
||||
if err != nil {
|
||||
monitor.Error(err)
|
||||
return err
|
||||
}
|
||||
|
||||
return deleteUser(monitor, user, k8sClient, desired)
|
||||
}
|
||||
|
||||
func deleteUser(
|
||||
monitor mntr.Monitor,
|
||||
user string,
|
||||
k8sClient kubernetes.ClientInt,
|
||||
desired *tree.Tree,
|
||||
) error {
|
||||
current := &tree.Tree{}
|
||||
|
||||
query, _, _, err := orbdb.AdaptFunc("", nil)(monitor, desired, current)
|
||||
query, _, _, _, _, err := orbdb.AdaptFunc("", nil, false, "database")(monitor, desired, current)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@@ -3,6 +3,9 @@ package kubernetes
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
|
||||
"github.com/caos/orbos/mntr"
|
||||
"github.com/caos/orbos/pkg/kubernetes"
|
||||
"github.com/caos/orbos/pkg/labels"
|
||||
@@ -21,6 +24,7 @@ func EnsureZitadelOperatorArtifacts(
|
||||
nodeselector map[string]string,
|
||||
tolerations []core.Toleration,
|
||||
imageRegistry string,
|
||||
gitops bool,
|
||||
) error {
|
||||
|
||||
monitor.WithFields(map[string]interface{}{
|
||||
@@ -78,6 +82,174 @@ func EnsureZitadelOperatorArtifacts(
|
||||
return err
|
||||
}
|
||||
|
||||
if !gitops {
|
||||
crd := `apiVersion: apiextensions.k8s.io/v1beta1
|
||||
kind: CustomResourceDefinition
|
||||
metadata:
|
||||
annotations:
|
||||
controller-gen.kubebuilder.io/version: v0.2.2
|
||||
creationTimestamp: null
|
||||
name: zitadels.caos.ch
|
||||
spec:
|
||||
group: caos.ch
|
||||
names:
|
||||
kind: Zitadel
|
||||
listKind: ZitadelList
|
||||
plural: zitadels
|
||||
singular: zitadel
|
||||
scope: ""
|
||||
validation:
|
||||
openAPIV3Schema:
|
||||
properties:
|
||||
apiVersion:
|
||||
description: 'APIVersion defines the versioned schema of this representation
|
||||
of an object. Servers should convert recognized schemas to the latest
|
||||
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
|
||||
type: string
|
||||
kind:
|
||||
description: 'Kind is a string value representing the REST resource this
|
||||
object represents. Servers may infer this from the endpoint the client
|
||||
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
|
||||
type: string
|
||||
metadata:
|
||||
type: object
|
||||
spec:
|
||||
properties:
|
||||
iam:
|
||||
type: object
|
||||
kind:
|
||||
type: string
|
||||
spec:
|
||||
properties:
|
||||
customImageRegistry:
|
||||
description: 'Use this registry to pull the zitadel operator image
|
||||
from @default: ghcr.io'
|
||||
type: string
|
||||
databaseCrd:
|
||||
properties:
|
||||
name:
|
||||
type: string
|
||||
namespace:
|
||||
type: string
|
||||
type: object
|
||||
gitops:
|
||||
type: boolean
|
||||
nodeSelector:
|
||||
additionalProperties:
|
||||
type: string
|
||||
type: object
|
||||
selfReconciling:
|
||||
type: boolean
|
||||
tolerations:
|
||||
items:
|
||||
description: The pod this Toleration is attached to tolerates
|
||||
any taint that matches the triple <key,value,effect> using the
|
||||
matching operator <operator>.
|
||||
properties:
|
||||
effect:
|
||||
description: Effect indicates the taint effect to match. Empty
|
||||
means match all taint effects. When specified, allowed values
|
||||
are NoSchedule, PreferNoSchedule and NoExecute.
|
||||
type: string
|
||||
key:
|
||||
description: Key is the taint key that the toleration applies
|
||||
to. Empty means match all taint keys. If the key is empty,
|
||||
operator must be Exists; this combination means to match
|
||||
all values and all keys.
|
||||
type: string
|
||||
operator:
|
||||
description: Operator represents a key's relationship to the
|
||||
value. Valid operators are Exists and Equal. Defaults to
|
||||
Equal. Exists is equivalent to wildcard for value, so that
|
||||
a pod can tolerate all taints of a particular category.
|
||||
type: string
|
||||
tolerationSeconds:
|
||||
description: TolerationSeconds represents the period of time
|
||||
the toleration (which must be of effect NoExecute, otherwise
|
||||
this field is ignored) tolerates the taint. By default,
|
||||
it is not set, which means tolerate the taint forever (do
|
||||
not evict). Zero and negative values will be treated as
|
||||
0 (evict immediately) by the system.
|
||||
format: int64
|
||||
type: integer
|
||||
value:
|
||||
description: Value is the taint value the toleration matches
|
||||
to. If the operator is Exists, the value should be empty,
|
||||
otherwise just a regular string.
|
||||
type: string
|
||||
type: object
|
||||
type: array
|
||||
verbose:
|
||||
type: boolean
|
||||
version:
|
||||
type: string
|
||||
required:
|
||||
- selfReconciling
|
||||
- verbose
|
||||
type: object
|
||||
version:
|
||||
type: string
|
||||
required:
|
||||
- iam
|
||||
- kind
|
||||
- spec
|
||||
- version
|
||||
type: object
|
||||
status:
|
||||
type: object
|
||||
type: object
|
||||
version: v1
|
||||
versions:
|
||||
- name: v1
|
||||
served: true
|
||||
storage: true
|
||||
status:
|
||||
acceptedNames:
|
||||
kind: ""
|
||||
plural: ""
|
||||
conditions: []
|
||||
storedVersions: []`
|
||||
|
||||
crdDefinition := &unstructured.Unstructured{}
|
||||
if err := yaml.Unmarshal([]byte(crd), &crdDefinition.Object); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := client.ApplyCRDResource(
|
||||
crdDefinition,
|
||||
); err != nil {
|
||||
return err
|
||||
}
|
||||
monitor.WithFields(map[string]interface{}{
|
||||
"version": version,
|
||||
}).Debug("Database Operator crd ensured")
|
||||
}
|
||||
|
||||
var (
|
||||
cmd = []string{"/zitadelctl", "operator"}
|
||||
volumes []core.Volume
|
||||
volumeMounts []core.VolumeMount
|
||||
)
|
||||
|
||||
if gitops {
|
||||
cmd = append(cmd, "--gitops", "-f", "/secrets/orbconfig")
|
||||
volumes = []core.Volume{{
|
||||
Name: "orbconfig",
|
||||
VolumeSource: core.VolumeSource{
|
||||
Secret: &core.SecretVolumeSource{
|
||||
SecretName: "caos",
|
||||
},
|
||||
},
|
||||
}}
|
||||
volumeMounts = []core.VolumeMount{{
|
||||
Name: "orbconfig",
|
||||
ReadOnly: true,
|
||||
MountPath: "/secrets",
|
||||
}}
|
||||
} else {
|
||||
cmd = append(cmd, "--kubeconfig", "")
|
||||
}
|
||||
|
||||
deployment := &apps.Deployment{
|
||||
ObjectMeta: mach.ObjectMeta{
|
||||
Name: nameLabels.Name(),
|
||||
@@ -99,18 +271,14 @@ func EnsureZitadelOperatorArtifacts(
|
||||
Name: "zitadel",
|
||||
ImagePullPolicy: core.PullIfNotPresent,
|
||||
Image: fmt.Sprintf("%s/caos/zitadel-operator:%s", imageRegistry, version),
|
||||
Command: []string{"/zitadelctl", "operator", "-f", "/secrets/orbconfig"},
|
||||
Command: cmd,
|
||||
Args: []string{},
|
||||
Ports: []core.ContainerPort{{
|
||||
Name: "metrics",
|
||||
ContainerPort: 2112,
|
||||
Protocol: "TCP",
|
||||
}},
|
||||
VolumeMounts: []core.VolumeMount{{
|
||||
Name: "orbconfig",
|
||||
ReadOnly: true,
|
||||
MountPath: "/secrets",
|
||||
}},
|
||||
VolumeMounts: volumeMounts,
|
||||
Resources: core.ResourceRequirements{
|
||||
Limits: core.ResourceList{
|
||||
"cpu": resource.MustParse("500m"),
|
||||
@@ -122,16 +290,9 @@ func EnsureZitadelOperatorArtifacts(
|
||||
},
|
||||
},
|
||||
}},
|
||||
NodeSelector: nodeselector,
|
||||
Tolerations: tolerations,
|
||||
Volumes: []core.Volume{{
|
||||
Name: "orbconfig",
|
||||
VolumeSource: core.VolumeSource{
|
||||
Secret: &core.SecretVolumeSource{
|
||||
SecretName: "caos",
|
||||
},
|
||||
},
|
||||
}},
|
||||
NodeSelector: nodeselector,
|
||||
Tolerations: tolerations,
|
||||
Volumes: volumes,
|
||||
TerminationGracePeriodSeconds: int64Ptr(10),
|
||||
},
|
||||
},
|
||||
@@ -170,7 +331,8 @@ func EnsureDatabaseArtifacts(
|
||||
version string,
|
||||
nodeselector map[string]string,
|
||||
tolerations []core.Toleration,
|
||||
imageRegistry string) error {
|
||||
imageRegistry string,
|
||||
gitops bool) error {
|
||||
|
||||
monitor.WithFields(map[string]interface{}{
|
||||
"database": version,
|
||||
@@ -227,6 +389,167 @@ func EnsureDatabaseArtifacts(
|
||||
return err
|
||||
}
|
||||
|
||||
if !gitops {
|
||||
crd := `apiVersion: apiextensions.k8s.io/v1beta1
|
||||
kind: CustomResourceDefinition
|
||||
metadata:
|
||||
annotations:
|
||||
controller-gen.kubebuilder.io/version: v0.2.2
|
||||
creationTimestamp: null
|
||||
name: databases.caos.ch
|
||||
spec:
|
||||
group: caos.ch
|
||||
names:
|
||||
kind: Database
|
||||
listKind: DatabaseList
|
||||
plural: databases
|
||||
singular: database
|
||||
scope: ""
|
||||
validation:
|
||||
openAPIV3Schema:
|
||||
properties:
|
||||
apiVersion:
|
||||
description: 'APIVersion defines the versioned schema of this representation
|
||||
of an object. Servers should convert recognized schemas to the latest
|
||||
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
|
||||
type: string
|
||||
kind:
|
||||
description: 'Kind is a string value representing the REST resource this
|
||||
object represents. Servers may infer this from the endpoint the client
|
||||
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
|
||||
type: string
|
||||
metadata:
|
||||
type: object
|
||||
spec:
|
||||
properties:
|
||||
database:
|
||||
type: object
|
||||
kind:
|
||||
type: string
|
||||
spec:
|
||||
properties:
|
||||
customImageRegistry:
|
||||
description: 'Use this registry to pull the Database operator image
|
||||
from @default: ghcr.io'
|
||||
type: string
|
||||
gitOps:
|
||||
type: boolean
|
||||
nodeSelector:
|
||||
additionalProperties:
|
||||
type: string
|
||||
type: object
|
||||
selfReconciling:
|
||||
type: boolean
|
||||
tolerations:
|
||||
items:
|
||||
description: The pod this Toleration is attached to tolerates
|
||||
any taint that matches the triple <key,value,effect> using the
|
||||
matching operator <operator>.
|
||||
properties:
|
||||
effect:
|
||||
description: Effect indicates the taint effect to match. Empty
|
||||
means match all taint effects. When specified, allowed values
|
||||
are NoSchedule, PreferNoSchedule and NoExecute.
|
||||
type: string
|
||||
key:
|
||||
description: Key is the taint key that the toleration applies
|
||||
to. Empty means match all taint keys. If the key is empty,
|
||||
operator must be Exists; this combination means to match
|
||||
all values and all keys.
|
||||
type: string
|
||||
operator:
|
||||
description: Operator represents a key's relationship to the
|
||||
value. Valid operators are Exists and Equal. Defaults to
|
||||
Equal. Exists is equivalent to wildcard for value, so that
|
||||
a pod can tolerate all taints of a particular category.
|
||||
type: string
|
||||
tolerationSeconds:
|
||||
description: TolerationSeconds represents the period of time
|
||||
the toleration (which must be of effect NoExecute, otherwise
|
||||
this field is ignored) tolerates the taint. By default,
|
||||
it is not set, which means tolerate the taint forever (do
|
||||
not evict). Zero and negative values will be treated as
|
||||
0 (evict immediately) by the system.
|
||||
format: int64
|
||||
type: integer
|
||||
value:
|
||||
description: Value is the taint value the toleration matches
|
||||
to. If the operator is Exists, the value should be empty,
|
||||
otherwise just a regular string.
|
||||
type: string
|
||||
type: object
|
||||
type: array
|
||||
verbose:
|
||||
type: boolean
|
||||
version:
|
||||
type: string
|
||||
required:
|
||||
- selfReconciling
|
||||
- verbose
|
||||
type: object
|
||||
version:
|
||||
type: string
|
||||
required:
|
||||
- database
|
||||
- kind
|
||||
- spec
|
||||
- version
|
||||
type: object
|
||||
status:
|
||||
type: object
|
||||
type: object
|
||||
version: v1
|
||||
versions:
|
||||
- name: v1
|
||||
served: true
|
||||
storage: true
|
||||
status:
|
||||
acceptedNames:
|
||||
kind: ""
|
||||
plural: ""
|
||||
conditions: []
|
||||
storedVersions: []`
|
||||
|
||||
crdDefinition := &unstructured.Unstructured{}
|
||||
if err := yaml.Unmarshal([]byte(crd), &crdDefinition.Object); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := client.ApplyCRDResource(
|
||||
crdDefinition,
|
||||
); err != nil {
|
||||
return err
|
||||
}
|
||||
monitor.WithFields(map[string]interface{}{
|
||||
"version": version,
|
||||
}).Debug("Database Operator crd ensured")
|
||||
}
|
||||
|
||||
var (
|
||||
cmd = []string{"/zitadelctl", "database"}
|
||||
volumes []core.Volume
|
||||
volumeMounts []core.VolumeMount
|
||||
)
|
||||
|
||||
if gitops {
|
||||
cmd = append(cmd, "--gitops", "-f", "/secrets/orbconfig")
|
||||
volumes = []core.Volume{{
|
||||
Name: "orbconfig",
|
||||
VolumeSource: core.VolumeSource{
|
||||
Secret: &core.SecretVolumeSource{
|
||||
SecretName: "caos",
|
||||
},
|
||||
},
|
||||
}}
|
||||
volumeMounts = []core.VolumeMount{{
|
||||
Name: "orbconfig",
|
||||
ReadOnly: true,
|
||||
MountPath: "/secrets",
|
||||
}}
|
||||
} else {
|
||||
cmd = append(cmd, "--kubeconfig", "")
|
||||
}
|
||||
|
||||
deployment := &apps.Deployment{
|
||||
ObjectMeta: mach.ObjectMeta{
|
||||
Name: "database-operator",
|
||||
@@ -248,18 +571,14 @@ func EnsureDatabaseArtifacts(
|
||||
Name: "database",
|
||||
ImagePullPolicy: core.PullIfNotPresent,
|
||||
Image: fmt.Sprintf("%s/caos/zitadel-operator:%s", imageRegistry, version),
|
||||
Command: []string{"/zitadelctl", "database", "-f", "/secrets/orbconfig"},
|
||||
Command: cmd,
|
||||
Args: []string{},
|
||||
Ports: []core.ContainerPort{{
|
||||
Name: "metrics",
|
||||
ContainerPort: 2112,
|
||||
Protocol: "TCP",
|
||||
}},
|
||||
VolumeMounts: []core.VolumeMount{{
|
||||
Name: "orbconfig",
|
||||
ReadOnly: true,
|
||||
MountPath: "/secrets",
|
||||
}},
|
||||
VolumeMounts: volumeMounts,
|
||||
Resources: core.ResourceRequirements{
|
||||
Limits: core.ResourceList{
|
||||
"cpu": resource.MustParse("500m"),
|
||||
@@ -271,16 +590,9 @@ func EnsureDatabaseArtifacts(
|
||||
},
|
||||
},
|
||||
}},
|
||||
NodeSelector: nodeselector,
|
||||
Tolerations: tolerations,
|
||||
Volumes: []core.Volume{{
|
||||
Name: "orbconfig",
|
||||
VolumeSource: core.VolumeSource{
|
||||
Secret: &core.SecretVolumeSource{
|
||||
SecretName: "caos",
|
||||
},
|
||||
},
|
||||
}},
|
||||
NodeSelector: nodeselector,
|
||||
Tolerations: tolerations,
|
||||
Volumes: volumes,
|
||||
TerminationGracePeriodSeconds: int64Ptr(10),
|
||||
},
|
||||
},
|
||||
|
Reference in New Issue
Block a user