diff --git a/charts/hookd/Feature.yaml b/charts/hookd/Feature.yaml index ee8308af..10b8bb45 100644 --- a/charts/hookd/Feature.yaml +++ b/charts/hookd/Feature.yaml @@ -30,6 +30,11 @@ values: displayName: Google service account computed: template: '"{{.Management.hookd_google_service_account_email}}"' + clusterMigrationRedirect: + description: Cluster reference for migration purposes (comma separated key=val) + displayName: Cluster migration redirect + config: + type: string image.imagePullPolicy: config: type: string diff --git a/charts/hookd/templates/secret.yaml b/charts/hookd/templates/secret.yaml index 2eeef169..58605d6e 100644 --- a/charts/hookd/templates/secret.yaml +++ b/charts/hookd/templates/secret.yaml @@ -27,3 +27,4 @@ stringData: HOOKD_NAIS_API_ADDRESS: "{{ .Values.naisAPI.address }}" HOOKD_NAIS_API_INSECURE_CONNECTION: "{{ .Values.naisAPI.insecureConnection }}" OTEL_EXPORTER_OTLP_ENDPOINT: "{{ .Values.otelExporterOtlpEndpoint }}" + HOOKD_CLUSTER_MIGRATION_REDIRECT: "{{ .Values.clusterMigrationRedirect }}" diff --git a/charts/hookd/values.yaml b/charts/hookd/values.yaml index 47681c19..35fcd0d0 100644 --- a/charts/hookd/values.yaml +++ b/charts/hookd/values.yaml @@ -45,3 +45,5 @@ imagePullSecrets: [] naisAPI: address: "nais-api:3001" insecureConnection: "false" + +clusterMigrationRedirect: \ No newline at end of file diff --git a/cmd/hookd/main.go b/cmd/hookd/main.go index f7c86061..19218462 100644 --- a/cmd/hookd/main.go +++ b/cmd/hookd/main.go @@ -172,8 +172,12 @@ func run() error { } func startGrpcServer(cfg config.Config, db database.DeploymentStore, apikeys database.ApiKeyStore) (*grpc.Server, dispatchserver.DispatchServer, error) { + clusterRedirects, err := parseKeyVal(cfg.ClusterMigrationRedirect) + if err != nil { + return nil, nil, fmt.Errorf("unable to parse cluster migration redirects: %v", err) + } dispatchServer := dispatchserver.New(db) - deployServer := deployserver.New(dispatchServer, db) + deployServer := deployserver.New(dispatchServer, db, clusterRedirects) unaryInterceptors := make([]grpc.UnaryServerInterceptor, 0) streamInterceptors := make([]grpc.StreamServerInterceptor, 0) diff --git a/pkg/grpc/deployserver/deployserver.go b/pkg/grpc/deployserver/deployserver.go index f0ea56f3..f9237379 100644 --- a/pkg/grpc/deployserver/deployserver.go +++ b/pkg/grpc/deployserver/deployserver.go @@ -20,12 +20,14 @@ type deployServer struct { pb.UnimplementedDeployServer dispatchServer dispatchserver.DispatchServer deploymentStore database.DeploymentStore + redirect map[string]string } -func New(dispatchServer dispatchserver.DispatchServer, deploymentStore database.DeploymentStore) pb.DeployServer { +func New(dispatchServer dispatchserver.DispatchServer, deploymentStore database.DeploymentStore, redirect map[string]string) pb.DeployServer { return &deployServer{ deploymentStore: deploymentStore, dispatchServer: dispatchServer, + redirect: redirect, } } @@ -105,6 +107,14 @@ func (ds *deployServer) Deploy(ctx context.Context, request *pb.DeploymentReques logger := log.WithFields(request.LogFields()) logger.Infof("Received deployment request") + for requestCluster, targetCluster := range ds.redirect { + if request.GetCluster() == requestCluster { + request.Cluster = targetCluster + logger.Infof("Redirecting deployment from %s to %s", requestCluster, targetCluster) + break + } + } + logger.Debugf("Writing deployment to database") err = ds.addToDatabase(ctx, request) if err != nil { diff --git a/pkg/hookd/config/config.go b/pkg/hookd/config/config.go index 571ca8bf..9ebb382f 100644 --- a/pkg/hookd/config/config.go +++ b/pkg/hookd/config/config.go @@ -34,6 +34,7 @@ type Config struct { ProvisionKey string `json:"provision-key"` NaisAPIAddress string `json:"nais-api-address"` NaisAPIInsecureConnection bool `json:"nais-api-insecure-connection"` + ClusterMigrationRedirect []string `json:"cluster-migration-redirect"` } const ( @@ -58,6 +59,7 @@ const ( ProvisionKey = "provision-key" NaisAPIAddress = "nais-api-address" NaisAPIInsecureConnection = "nais-api-insecure-connection" + ClusterMigrationRedirect = "cluster-migration-redirect" ) // Bind environment variables provided by the NAIS platform @@ -100,6 +102,7 @@ func Initialize() *Config { flag.Bool(NaisAPIInsecureConnection, false, "Insecure connection to API server") flag.String(NaisAPIAddress, "localhost:3001", "NAIS API target") + flag.StringSlice(ClusterMigrationRedirect, []string{}, "Mapping cluster to redirect: cluster=targetCluster") return &Config{} }