Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions internal/deployer/crs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ import (

// generateCRS generates the Central Resource Secret using roxctl
func (d *Deployer) generateCRS(ctx context.Context, clusterName string) (string, error) {
d.logger.Info("Generating CRS with roxctl...")
crsName := fmt.Sprintf("%s-crs", clusterName)
Comment thread
AlexVulaj marked this conversation as resolved.
d.logger.Infof("Generating CRS named %q with roxctl...", crsName)

result, err := d.runRoxctl(ctx, RoxctlOptions{
Args: []string{
"-e", d.centralEndpoint,
"central",
"crs",
"generate",
clusterName,
crsName,
"--output=-", // Output to stdout
},
UseAuthentication: true,
Expand Down
24 changes: 16 additions & 8 deletions internal/deployer/deploy_via_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/stackrox/roxie/internal/env"
"github.com/stackrox/roxie/internal/helpers"
"gopkg.in/yaml.v3"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
)

var (
Expand Down Expand Up @@ -623,7 +624,19 @@ func (d *Deployer) deploySecuredClusterOperator(ctx context.Context, resources s
return fmt.Errorf("failed to prepare namespace: %w", err)
}

clusterName := generateClusterName()
securedClusterCR, err := d.createSecuredClusterCR(resources)
if err != nil {
return fmt.Errorf("failed to create SecuredCluster CR: %w", err)
}

clusterName, found, err := unstructured.NestedString(securedClusterCR, "spec", "clusterName")
if err != nil {
return fmt.Errorf("failed to get cluster name from SecuredCluster CR: %w", err)
}
if !found || clusterName == "" {
return fmt.Errorf("cluster name not found in SecuredCluster CR")
}
d.logger.Infof("Using cluster name: %s", clusterName)

crsContent, err := d.generateCRS(ctx, clusterName)
if err != nil {
Expand All @@ -634,11 +647,6 @@ func (d *Deployer) deploySecuredClusterOperator(ctx context.Context, resources s
return fmt.Errorf("failed to apply CRS: %w", err)
}

securedClusterCR, err := d.createSecuredClusterCR(clusterName, resources)
if err != nil {
return fmt.Errorf("failed to create SecuredCluster CR: %w", err)
}

if err := d.applySecuredClusterCR(ctx, securedClusterCR); err != nil {
return fmt.Errorf("failed to apply SecuredCluster CR: %w", err)
}
Expand All @@ -656,7 +664,7 @@ func (d *Deployer) deploySecuredClusterOperator(ctx context.Context, resources s
}

// createSecuredClusterCR creates the SecuredCluster custom resource.
func (d *Deployer) createSecuredClusterCR(clusterName, resources string) (map[string]interface{}, error) {
func (d *Deployer) createSecuredClusterCR(resources string) (map[string]interface{}, error) {
base := map[string]interface{}{
"apiVersion": "platform.stackrox.io/v1alpha1",
"kind": "SecuredCluster",
Expand All @@ -668,7 +676,7 @@ func (d *Deployer) createSecuredClusterCR(clusterName, resources string) (map[st
},
},
"spec": map[string]interface{}{
"clusterName": clusterName,
"clusterName": generateClusterName(), // Just a default, can be overwritten.
"centralEndpoint": internalCentralEndpoint(d.centralNamespace),
"imagePullSecrets": []map[string]string{
{"name": "stackrox"},
Expand Down
Loading