Skip to content

Commit e9babce

Browse files
author
Moritz Clasmeier
committed
Merge branch 'main' into backup/mc/new-config-2
2 parents 20676d0 + b4991fe commit e9babce

6 files changed

Lines changed: 31 additions & 34 deletions

File tree

internal/deployer/deploy_via_operator.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ func (d *Deployer) ensureOperatorDeployed(ctx context.Context) error {
118118
func (d *Deployer) deployCentralOperator(ctx context.Context) error {
119119
d.logger.Info("🚀 Deploying Central via Operator...")
120120

121-
if err := d.prepareNamespace(ctx, d.config.Central.Namespace); err != nil {
121+
needPullSecrets := env.GetCurrentClusterType() != types.ClusterTypeInfraOpenShift4
122+
if err := d.prepareNamespace(ctx, d.config.Central.Namespace, needPullSecrets); err != nil {
122123
return fmt.Errorf("failed to prepare namespace: %w", err)
123124
}
124125

@@ -190,14 +191,14 @@ func (d *Deployer) getDeployedOperatorImage(ctx context.Context) (string, error)
190191
}
191192

192193
// prepareNamespace creates pull secrets in the namespace if needed
193-
func (d *Deployer) prepareNamespace(ctx context.Context, namespace string) error {
194+
func (d *Deployer) prepareNamespace(ctx context.Context, namespace string, needPullSecrets bool) error {
194195
d.logger.Infof("Preparing namespace %s", namespace)
195196

196197
if err := d.ensureNamespaceExists(namespace); err != nil {
197198
return err
198199
}
199200

200-
if env.GetCurrentClusterType() != types.ClusterTypeInfraOpenShift4 {
201+
if needPullSecrets {
201202
if err := d.ensurePullSecretExists(ctx, namespace); err != nil {
202203
return fmt.Errorf("ensuring image pull secret exists: %w", err)
203204
}
@@ -207,9 +208,11 @@ func (d *Deployer) prepareNamespace(ctx context.Context, namespace string) error
207208
}
208209

209210
func (d *Deployer) ensurePullSecretExists(ctx context.Context, namespace string) error {
210-
// Assemble pull secret YAML from pre-verified credentials
211-
pullSecretYAML := d.dockerAuth.CreatePullSecretYAMLFromCredentials(d.dockerCreds, namespace)
211+
if d.dockerCreds == nil {
212+
return errors.New("no pull secrets available to set up on the cluster")
213+
}
212214

215+
pullSecretYAML := d.dockerAuth.CreatePullSecretYAMLFromCredentials(*d.dockerCreds, namespace)
213216
_, err := d.runKubectl(ctx, k8s.KubectlOptions{
214217
Args: []string{"apply", "-f", "-"},
215218
Stdin: strings.NewReader(pullSecretYAML),
@@ -584,7 +587,8 @@ func (d *Deployer) configureCentralEndpoint(ctx context.Context) error {
584587
func (d *Deployer) deploySecuredClusterOperator(ctx context.Context) error {
585588
d.logger.Info("🚀 Deploying SecuredCluster via Operator...")
586589

587-
if err := d.prepareNamespace(ctx, d.config.SecuredCluster.Namespace); err != nil {
590+
needPullSecrets := env.GetCurrentClusterType() != types.ClusterTypeInfraOpenShift4
591+
if err := d.prepareNamespace(ctx, d.config.SecuredCluster.Namespace, needPullSecrets); err != nil {
588592
return fmt.Errorf("failed to prepare namespace: %w", err)
589593
}
590594

internal/deployer/deployer.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,13 @@ type Deployer struct {
5151
config Config
5252

5353
// State
54-
centralEndpoint string
55-
centralPassword string
56-
roxCACertFile string
57-
tempDir string
58-
portForward *portforward.Manager
59-
portForwardPID int
54+
centralEndpoint string
55+
centralPassword string
56+
roxCACertFile string
57+
tempDir string
58+
portForward *portforward.Manager
59+
portForwardPID int
60+
useOperatorPullSecrets bool
6061
}
6162

6263
type ResourceToDelete struct {
@@ -124,6 +125,7 @@ func (d *Deployer) deleteCentralResources(ctx context.Context) error {
124125
{Name: "central-db-backup", Kind: "pvc"},
125126
{Name: "admin-password", Kind: "secret"},
126127
{Name: "scanner-db-password", Kind: "secret", OwnerName: centralCrName},
128+
{Name: "stackrox-central-helm", Kind: "configmap"},
127129
} {
128130
d.logger.Dimf("Attempting to delete %s/%s", resource.Kind, resource.Name)
129131
if resource.OwnerName != "" {

internal/deployer/operator.go

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/stackrox/roxie/internal/env"
1818
"github.com/stackrox/roxie/internal/k8s"
1919
"github.com/stackrox/roxie/internal/ocihelper"
20+
"github.com/stackrox/roxie/internal/types"
2021
)
2122

2223
const (
@@ -319,12 +320,14 @@ func (d *Deployer) deployOperatorFromCSV(ctx context.Context, bundleDir string)
319320
}
320321

321322
serviceAccountName := deploymentSpec["service_account"].(string)
323+
d.useOperatorPullSecrets = d.config.Roxie.KonfluxImages && env.GetCurrentClusterType() != types.ClusterTypeInfraOpenShift4
322324

323325
d.logger.Info("📋 Operator deployment plan:")
324326
d.logger.Dim(fmt.Sprintf(" • Namespace: %s", operatorNamespace))
325327
d.logger.Dim(fmt.Sprintf(" • ServiceAccount: %s", serviceAccountName))
328+
d.logger.Dim(fmt.Sprintf(" • Setting up pull secrets: %v", d.useOperatorPullSecrets))
326329

327-
if err := d.createOperatorNamespace(ctx); err != nil {
330+
if err := d.prepareNamespace(ctx, operatorNamespace, d.useOperatorPullSecrets); err != nil {
328331
return err
329332
}
330333

@@ -392,24 +395,6 @@ func (d *Deployer) parseCSVDeploymentSpec(csvFile string) (map[string]interface{
392395
return deploymentSpec, nil
393396
}
394397

395-
// createOperatorNamespace creates the operator namespace
396-
func (d *Deployer) createOperatorNamespace(ctx context.Context) error {
397-
nsYAML := fmt.Sprintf(`apiVersion: v1
398-
kind: Namespace
399-
metadata:
400-
name: %s
401-
labels:
402-
name: %s
403-
app.kubernetes.io/managed-by: roxie
404-
`, operatorNamespace, operatorNamespace)
405-
406-
_, err := d.runKubectl(ctx, k8s.KubectlOptions{
407-
Args: []string{"apply", "-f", "-"},
408-
Stdin: strings.NewReader(nsYAML),
409-
})
410-
return err
411-
}
412-
413398
// createServiceAccount creates a service account
414399
func (d *Deployer) createServiceAccount(ctx context.Context, namespace, name string) error {
415400
sa := map[string]interface{}{
@@ -422,6 +407,12 @@ func (d *Deployer) createServiceAccount(ctx context.Context, namespace, name str
422407
},
423408
}
424409

410+
if d.useOperatorPullSecrets {
411+
sa["imagePullSecrets"] = []map[string]string{
412+
{"name": "stackrox"},
413+
}
414+
}
415+
425416
yamlData, err := yaml.Marshal(sa)
426417
if err != nil {
427418
return fmt.Errorf("failed to marshal ServiceAccount '%s/%s': %w", namespace, name, err)

internal/deployer/operator_olm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (d *Deployer) deployOperatorViaOLM(ctx context.Context) error {
4040
indexImage := d.getOperatorIndexImage()
4141
d.logger.Infof("Index image: %s", indexImage)
4242

43-
if err := d.createOperatorNamespace(ctx); err != nil {
43+
if err := d.prepareNamespace(ctx, operatorNamespace, false); err != nil {
4444
return err
4545
}
4646

internal/dockerauth/dockerauth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ func (d *DockerAuth) VerifyCredentials(username, password string) error {
216216
}
217217

218218
// CreatePullSecretYAMLFromCredentials creates Kubernetes pull secret YAML from verified credentials.
219-
func (d *DockerAuth) CreatePullSecretYAMLFromCredentials(creds *Credentials, namespace string) string {
219+
func (d *DockerAuth) CreatePullSecretYAMLFromCredentials(creds Credentials, namespace string) string {
220220
// Create auth string
221221
authString := fmt.Sprintf("%s:%s", creds.Username, creds.Password)
222222
encodedAuth := base64.StdEncoding.EncodeToString([]byte(authString))

internal/dockerauth/dockerauth_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func TestGetAndVerifyCredentialsFromEnv(t *testing.T) {
3131
}
3232

3333
// Test creating YAML from credentials
34-
yamlText := da.CreatePullSecretYAMLFromCredentials(creds, "ns")
34+
yamlText := da.CreatePullSecretYAMLFromCredentials(*creds, "ns")
3535

3636
// Verify YAML structure
3737
if !strings.Contains(yamlText, "apiVersion: v1") {

0 commit comments

Comments
 (0)