Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 60 additions & 38 deletions cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,9 @@ func runDeploy(cmd *cobra.Command, args []string) error {
return err
}

// Cluster-config retrieval happens before the full config (and thus the configured deploy
// wait timeouts) is assembled, so give it its own short bounded context.
setupCtx, setupCancel := context.WithTimeout(context.Background(), 10*time.Minute)
defer setupCancel()
clusterConfig := deployer.DefaultConfig()
Comment thread
coderabbitai[bot] marked this conversation as resolved.

clusterConfig := retrieveClusterConfigForComponents(setupCtx, components)

deploySettings, err := assembleConfigForCommand(clusterConfig, deploySettingsFromArgs, skipUserConfig)
deploySettings, err := assembleConfigForCommand(&clusterConfig, deploySettingsFromArgs, skipUserConfig)
if err != nil {
return err
}
Expand Down Expand Up @@ -345,13 +340,9 @@ func runDeploy(cmd *cobra.Command, args []string) error {
}

if !dryRun {
roxieEnv := roxieenv.AssembleRoxieEnvironment(d.GetCentralDeploymentInfo())
m := manifest.RoxieManifest{
RoxieEnvironment: roxieEnv,
Config: deploySettings,
}
if err := manifest.CreateManifestSecretOnCluster(ctx, m); err != nil {
log.Warningf("Failed to save roxie manifest: %v", err)
if err := updateManifest(ctx, d, components, deploySettings); err != nil {
log.Warningf("Updating roxie manifest failed: %v", err)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're warning both here and inside updateManifest 😟

// Keep going.
}
}

Expand Down Expand Up @@ -402,30 +393,6 @@ func validateContainerizedCredentials(registry string, clusterType types.Cluster
return nil
}

func retrieveClusterConfigForComponents(
ctx context.Context,
components component.Component,
) *deployer.Config {
clusterManifest, err := manifest.LoadManifestSecret(ctx)
if err != nil {
if errors.Is(err, k8s.ErrResourceNotFound) {
log.Dim("No existing manifest found on cluster, starting from defaults")
} else {
log.Warningf("Failed to load manifest from cluster: %v", err)
}
return nil // Let's try to continue without manifest
}

if components == component.SecuredCluster && clusterManifest.Config.SecuredCluster.Spec != nil {
// Reusing these fields from the config stored on the cluster would cause problems
// during repeating sensor deploy & teardown cycles.
delete(clusterManifest.Config.SecuredCluster.Spec, "clusterName")
delete(clusterManifest.Config.SecuredCluster.Spec, "centralEndpoint")
}

return &clusterManifest.Config
}

func configureConfig(components component.Component, deploySettings *deployer.Config) error {
if deploySettings.Roxie.ClusterType == "" {
clusterType := env.GetAutoDetectedClusterType()
Expand Down Expand Up @@ -607,3 +574,58 @@ func generateClusterName() string {

return fmt.Sprintf("sensor-%d", randInt)
}

func updateManifest(ctx context.Context, d *deployer.Deployer, components component.Component, deploySettings deployer.Config) error {
newManifest := manifest.RoxieManifest{}

currentManifest, err := manifest.LoadManifestSecret(ctx)
if err != nil {
if errors.Is(err, k8s.ErrResourceNotFound) {
// No manifest on the cluster, probably due to an isolated SecuredCluster deployment with roxie
// on a cluster without a (roxie-deployed) central.
// In this case we don't need to merge anything, we will just create a new manifest with
// current deploySettings.
log.Dim("No existing roxie manifest found on cluster, starting from defaults")
} else {
log.Warningf("Failed to load roxie manifest from cluster: %v", err)
log.Warning("Skipping updating roxie manifest")
return err
}
}

// Manifest updating logic heavily depends on the components.
switch components {
case component.Both, component.All, component.Central:
// Includes central, create roxie manifest from scratch.
roxieEnv := roxieenv.AssembleRoxieEnvironment(d.GetCentralDeploymentInfo())
newManifest.RoxieEnvironment = roxieEnv
newManifest.Config = deploySettings
case component.SecuredCluster:
// If a previous manifest exists on cluster, update it to include the SecuredCluster settings.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if there are multiple secured clusters like in the performance test? 🤔

if currentManifest == nil {
newManifest.Config = deploySettings
} else {
log.Dim("Found existing roxie manifest on cluster, updating only SecuredCluster deployment settings")
newManifest = *currentManifest
newManifest.Config.SecuredCluster = deploySettings.SecuredCluster
}
case component.Operator:
// If a previous manifest exists on cluster, update it to include the Operator settings.
if currentManifest == nil {
newManifest.Config = deploySettings
} else {
log.Dim("Found existing roxie manifest on cluster, updating only Operator deployment settings")
newManifest = *currentManifest
newManifest.Config.Operator = deploySettings.Operator

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work well with multiple operators?

}
case component.AddOns:
// Nothing to write in this case.
return nil
}

if err := manifest.CreateManifestSecretOnCluster(ctx, newManifest); err != nil {
log.Warningf("Failed to save roxie manifest: %v", err)
}

return nil
}
Loading