Skip to content

Commit 5bcd644

Browse files
author
Moritz Clasmeier
committed
Merge branch 'main' into backup/mc/new-config-2
2 parents 9d862ea + a72a41a commit 5bcd644

2 files changed

Lines changed: 35 additions & 45 deletions

File tree

internal/deployer/deployer.go

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ var (
9090
"storageclasses",
9191
"validatingwebhookconfigurations",
9292
}
93-
)
9493

95-
const (
96-
injectedCABundleConfigMap = "injected-cabundle-stackrox-central-services"
94+
injectedCABundleConfigMapPrefix = "injected-cabundle-"
95+
injectedCABundleConfigMapCentral = injectedCABundleConfigMapPrefix + centralCrName
96+
injectedCABundleConfigMapSecuredCluster = injectedCABundleConfigMapPrefix + securedClusterCrName
9797
)
9898

9999
// Deployer is the base deployer for ACS
@@ -189,14 +189,13 @@ func (d *Deployer) deleteCentralResources(ctx context.Context, wait bool) error
189189
// Pause reconciliation for other controllers, not just our RHACS operator.
190190
// This is needed to ensure that there is no race causing the Cluster Network Operator
191191
// to re-create the injected-ca-bundle ConfigMap during resource deletion.
192-
err := d.preventOtherControllersFromReconciling(ctx)
193-
if err != nil {
194-
return fmt.Errorf("failed to prevent other controllers from reconciling: %w", err)
192+
if err := d.preventOtherControllersFromReconciling(ctx, component.Central); err != nil {
193+
return fmt.Errorf("failed to prevent other controllers from reconciling Central resources: %w", err)
195194
}
196195

197196
// Delete other resources by brute force.
198197
resourceKinds := d.filterResourceKinds(allInstallableCentralResourceKinds)
199-
err = d.deleteResources(ctx, d.config.Central.Namespace, resourceKinds, "-l=app.kubernetes.io/part-of=stackrox-central-services")
198+
err := d.deleteResources(ctx, d.config.Central.Namespace, resourceKinds, "-l=app.kubernetes.io/part-of=stackrox-central-services")
200199
if err != nil {
201200
return err
202201
}
@@ -206,9 +205,9 @@ func (d *Deployer) deleteCentralResources(ctx context.Context, wait bool) error
206205
{Name: "central-db-backup", Kind: "pvc", OwnerName: centralCrName},
207206
{Name: "admin-password", Kind: "secret"},
208207
{Name: "scanner-db-password", Kind: "secret", OwnerName: centralCrName},
209-
// In case the Cluster Network Operator has succeeded in re-creating the injectedCABundleConfigMap
208+
// In case the Cluster Network Operator has succeeded in re-creating the injected-cabundle configmap
210209
// after our operator has already deleted it.
211-
{Name: injectedCABundleConfigMap, Kind: "configmap"},
210+
{Name: injectedCABundleConfigMapCentral, Kind: "configmap"},
212211
} {
213212
d.logger.Dimf("Attempting to delete %s/%s", resource.Kind, resource.Name)
214213
if resource.OwnerName != "" {
@@ -243,17 +242,22 @@ func (d *Deployer) deleteCentralResources(ctx context.Context, wait bool) error
243242
return nil
244243
}
245244

246-
func (d *Deployer) preventOtherControllersFromReconciling(ctx context.Context) error {
247-
return d.preventCABundleInjection(ctx)
245+
func (d *Deployer) preventOtherControllersFromReconciling(ctx context.Context, comp component.Component) error {
246+
switch comp {
247+
case component.Central:
248+
return d.preventCABundleInjection(ctx, injectedCABundleConfigMapCentral, d.config.Central.Namespace)
249+
case component.SecuredCluster:
250+
return d.preventCABundleInjection(ctx, injectedCABundleConfigMapSecuredCluster, d.config.SecuredCluster.Namespace)
251+
default:
252+
return nil
253+
}
248254
}
249255

250-
func (d *Deployer) preventCABundleInjection(ctx context.Context) error {
251-
configMapName := injectedCABundleConfigMap
252-
256+
func (d *Deployer) preventCABundleInjection(ctx context.Context, configMapName, namespace string) error {
253257
d.logger.Info("Removing CNO label from injected-cabundle ConfigMap to prevent CNO from injecting the CA bundle during cleanup")
254258
_, err := d.runKubectl(ctx, k8s.KubectlOptions{
255259
Args: []string{
256-
"label", "configmap", configMapName, "-n", d.config.Central.Namespace,
260+
"label", "configmap", configMapName, "-n", namespace,
257261
"config.openshift.io/inject-trusted-cabundle-",
258262
},
259263
IgnoreErrors: true,
@@ -285,6 +289,13 @@ func (d *Deployer) deleteSecuredClusterResources(ctx context.Context, wait bool)
285289
}
286290
}
287291

292+
// Pause reconciliation for other controllers, not just our RHACS operator.
293+
// This is needed to ensure that there is no race causing the Cluster Network Operator
294+
// to re-create the injected-ca-bundle ConfigMap during resource deletion.
295+
if err := d.preventOtherControllersFromReconciling(ctx, component.SecuredCluster); err != nil {
296+
return fmt.Errorf("failed to prevent other controllers from reconciling SecuredCluster resources: %w", err)
297+
}
298+
288299
// In the meantime, delete other resources by brute force.
289300
resourceKinds := d.filterResourceKinds(allInstallableSecuredClusterResourceKinds)
290301
err := d.deleteResources(ctx, d.config.SecuredCluster.Namespace, resourceKinds, "-l=app.kubernetes.io/part-of=stackrox-secured-cluster-services")
@@ -297,6 +308,9 @@ func (d *Deployer) deleteSecuredClusterResources(ctx context.Context, wait bool)
297308
// We need to make sure that don't accidentally delete a scanner-db-password belonging to the central CR,
298309
// when both are deployed into the same namespace.
299310
{Name: "scanner-db-password", Kind: "secret", OwnerName: securedClusterCrName},
311+
// In case the Cluster Network Operator has succeeded in re-creating the injected-cabundle configmap
312+
// after our operator has already deleted it.
313+
{Name: injectedCABundleConfigMapSecuredCluster, Kind: "configmap"},
300314
} {
301315
d.logger.Dimf("Attempting to delete %s/%s", resource.Kind, resource.Name)
302316
if resource.OwnerName != "" {

internal/deployer/operator_olm.go

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,6 @@ func (d *Deployer) getOperatorIndexImage() string {
127127
func (d *Deployer) createCatalogSource(ctx context.Context, indexImage string) error {
128128
d.logger.Info("Creating CatalogSource...")
129129

130-
// Check if CatalogSource CRD supports securityContextConfig (OCP 4.14+).
131-
hasSecurityContextConfig, err := d.catalogSourceSupportsSecurityContextConfig(ctx)
132-
if err != nil {
133-
d.logger.Warning("Could not check CatalogSource CRD capabilities, proceeding without securityContextConfig")
134-
hasSecurityContextConfig = false
135-
}
136-
137130
catalogSource := map[string]interface{}{
138131
"apiVersion": "operators.coreos.com/v1alpha1",
139132
"kind": "CatalogSource",
@@ -145,24 +138,21 @@ func (d *Deployer) createCatalogSource(ctx context.Context, indexImage string) e
145138
"sourceType": "grpc",
146139
"image": indexImage,
147140
"displayName": "StackRox Operator Index",
141+
"grpcPodConfig": map[string]interface{}{
142+
"securityContextConfig": "restricted",
143+
},
148144
},
149145
}
150146

151-
// TODO(ROX-34499): Add security context config if supported.
152-
if hasSecurityContextConfig {
153-
spec := catalogSource["spec"].(map[string]interface{})
154-
spec["grpcPodConfig"] = map[string]interface{}{
155-
"securityContextConfig": "restricted",
156-
}
157-
}
158-
159147
yamlData, err := yaml.Marshal(catalogSource)
160148
if err != nil {
161149
return fmt.Errorf("failed to marshal CatalogSource: %w", err)
162150
}
163151

164152
_, err = d.runKubectl(ctx, k8s.KubectlOptions{
165-
Args: []string{"apply", "-f", "-"},
153+
// Apply with --validate=ignore because securityContextConfig may not
154+
// be in the CatalogSource CRD schema.
155+
Args: []string{"apply", "--validate=ignore", "-f", "-"},
166156
Stdin: bytes.NewReader(yamlData),
167157
})
168158
if err != nil {
@@ -173,20 +163,6 @@ func (d *Deployer) createCatalogSource(ctx context.Context, indexImage string) e
173163
return nil
174164
}
175165

176-
// catalogSourceSupportsSecurityContextConfig checks if the CatalogSource CRD supports securityContextConfig.
177-
func (d *Deployer) catalogSourceSupportsSecurityContextConfig(ctx context.Context) (bool, error) {
178-
result, err := d.runKubectl(ctx, k8s.KubectlOptions{
179-
Args: []string{"get", "crd", "catalogsources.operators.coreos.com", "-o", "yaml"},
180-
})
181-
if err != nil {
182-
return false, err
183-
}
184-
185-
// TODO(ROX-34499): this is overly optimistic and would incorrectly succeed if an api version
186-
// that contains this had "serving: false"
187-
return strings.Contains(result.Stdout, "securityContextConfig"), nil
188-
}
189-
190166
// createOperatorGroup creates the OperatorGroup.
191167
func (d *Deployer) createOperatorGroup(ctx context.Context) error {
192168
d.logger.Info("Creating OperatorGroup...")

0 commit comments

Comments
 (0)