Skip to content

Commit

Permalink
block cluster id change (#422)
Browse files Browse the repository at this point in the history
* block cluster id change


Co-authored-by: Naama Solomon <[email protected]>
  • Loading branch information
kerenlahav and I065450 authored Apr 14, 2024
1 parent 3baac1d commit 47d252d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM --platform=$BUILDPLATFORM golang:1.22.1-alpine as builder
FROM --platform=$BUILDPLATFORM golang:1.22.2-alpine as builder

WORKDIR /workspace
# Copy the Go Modules manifests
Expand Down
2 changes: 1 addition & 1 deletion api/common/utils/secret_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ var allowedSprigFunctions = map[string]interface{}{
// "typeIsLike": nil,
// "kindOf": nil,
// "kindIs": nil,
"deepEqual": nil,
"deepEqual": nil,

// OS:
// "env": nil,
Expand Down
1 change: 1 addition & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Config struct {
AllowedNamespaces []string `envconfig:"allowed_namespaces"`
EnableNamespaceSecrets bool `envconfig:"enable_namespace_secrets"`
ClusterID string `envconfig:"cluster_id"`
InitialClusterID string `envconfig:"initial_cluster_id"`
RetryBaseDelay time.Duration
RetryMaxDelay time.Duration
}
Expand Down
30 changes: 25 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,25 @@ limitations under the License.
package main

import (
"context"
"flag"
"os"

"github.com/SAP/sap-btp-service-operator/internal/utils"

"github.com/SAP/sap-btp-service-operator/api/v1/webhooks"
v1 "k8s.io/api/core/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"

"github.com/SAP/sap-btp-service-operator/internal/utils"

"k8s.io/client-go/rest"

"fmt"

"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/healthz"

"github.com/SAP/sap-btp-service-operator/api/v1/webhooks"
"sigs.k8s.io/controller-runtime/pkg/webhook"

logf "sigs.k8s.io/controller-runtime/pkg/log"

"github.com/SAP/sap-btp-service-operator/internal/config"
Expand Down Expand Up @@ -102,6 +104,13 @@ func main() {
os.Exit(1)
}

if len(config.Get().InitialClusterID) == 0 {
setupLog.Info("cluster secret not found, creating it")
createClusterSecret(mgr.GetClient())
} else if config.Get().InitialClusterID != config.Get().ClusterID {
panic(fmt.Sprintf("ClusterID changed, which is not supported. Please redeploy with --set cluster.id=%s", config.Get().InitialClusterID))
}

secretResolver := &utils.SecretResolver{
ManagementNamespace: config.Get().ManagementNamespace,
ReleaseNamespace: config.Get().ReleaseNamespace,
Expand Down Expand Up @@ -162,4 +171,15 @@ func main() {
setupLog.Error(err, "problem running manager")
os.Exit(1)
}

}

func createClusterSecret(client client.Client) {
clusterSecret := &v1.Secret{}
clusterSecret.Name = "sap-btp-operator-clusterid"
clusterSecret.Namespace = config.Get().ReleaseNamespace
clusterSecret.StringData = map[string]string{"INITIAL_CLUSTER_ID": config.Get().ClusterID}
if err := client.Create(context.Background(), clusterSecret); err != nil {
setupLog.Error(err, "failed to create cluster secret")
}
}
3 changes: 3 additions & 0 deletions sapbtp-operator-charts/templates/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ spec:
envFrom:
- configMapRef:
name: sap-btp-operator-config
- secretRef:
name: sap-btp-operator-clusterid
optional: true
{{- if and ( .Values.manager.image.sha ) ( .Values.manager.image.tag ) }}
image: "{{.Values.manager.image.repository}}:{{.Values.manager.image.tag}}@sha256:{{.Values.manager.image.sha}}"
{{- else if .Values.manager.image.sha}}
Expand Down

0 comments on commit 47d252d

Please sign in to comment.