Skip to content

Commit

Permalink
feat: add support for redirecting cluster deploys in hookd for migrat…
Browse files Browse the repository at this point in the history
…ion purposes

* add feature config flag ClusterMigrationRedirect
* add parsing of redirect key=value string and redirect deploys to
  desired cluster

oo-authored-by: Vegar Sechmann Molvig <[email protected]>
Co-authored-by: Roger Bjørnstad <[email protected]>
  • Loading branch information
Muni10 and rbjornstad committed Nov 19, 2024
1 parent 6ccfc94 commit 724cec3
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 2 deletions.
5 changes: 5 additions & 0 deletions charts/hookd/Feature.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions charts/hookd/templates/secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
2 changes: 2 additions & 0 deletions charts/hookd/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,5 @@ imagePullSecrets: []
naisAPI:
address: "nais-api:3001"
insecureConnection: "false"

clusterMigrationRedirect:
6 changes: 5 additions & 1 deletion cmd/hookd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
13 changes: 12 additions & 1 deletion pkg/grpc/deployserver/deployserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down Expand Up @@ -105,6 +107,15 @@ 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 {
logger.Infof("Checking for cluster migration redirect: %s -> %s", requestCluster, targetCluster)
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 {
Expand Down
1 change: 1 addition & 0 deletions pkg/hookd/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit 724cec3

Please sign in to comment.