Skip to content

Commit 2ac8465

Browse files
author
Moritz Clasmeier
committed
Merge branch 'main' into backup/mc/new-config-2
2 parents 5fb1130 + cd8a8d5 commit 2ac8465

2 files changed

Lines changed: 40 additions & 17 deletions

File tree

internal/deployer/deployer.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ var (
9292
}
9393
)
9494

95+
const (
96+
injectedCABundleConfigMap = "injected-cabundle-stackrox-central-services"
97+
)
98+
9599
// Deployer is the base deployer for ACS
96100
type Deployer struct {
97101
// Influencing roxies mode of operation.
@@ -202,6 +206,9 @@ func (d *Deployer) deleteCentralResources(ctx context.Context, wait bool) error
202206
{Name: "central-db-backup", Kind: "pvc", OwnerName: centralCrName},
203207
{Name: "admin-password", Kind: "secret"},
204208
{Name: "scanner-db-password", Kind: "secret", OwnerName: centralCrName},
209+
// In case the Cluster Network Operator has succeeded in re-creating the injectedCABundleConfigMap
210+
// after our operator has already deleted it.
211+
{Name: injectedCABundleConfigMap, Kind: "configmap"},
205212
} {
206213
d.logger.Dimf("Attempting to delete %s/%s", resource.Kind, resource.Name)
207214
if resource.OwnerName != "" {
@@ -241,11 +248,7 @@ func (d *Deployer) preventOtherControllersFromReconciling(ctx context.Context) e
241248
}
242249

243250
func (d *Deployer) preventCABundleInjection(ctx context.Context) error {
244-
configMapName := "injected-cabundle-stackrox-central-services"
245-
246-
if !d.doesResourceExist(ctx, "configmap", configMapName, d.config.Central.Namespace) {
247-
return nil
248-
}
251+
configMapName := injectedCABundleConfigMap
249252

250253
d.logger.Info("Removing CNO label from injected-cabundle ConfigMap to prevent CNO from injecting the CA bundle during cleanup")
251254
_, err := d.runKubectl(ctx, k8s.KubectlOptions{

internal/deployer/operator_olm.go

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,26 +72,46 @@ func (d *Deployer) deployOperatorViaOLM(ctx context.Context) error {
7272
return nil
7373
}
7474

75-
// checkOLMInstalled checks if OLM is installed in the cluster.
75+
// checkOLMInstalled checks if OLM is installed in the cluster by verifying
76+
// the API server is ready to serve the required OLM resource types.
7677
func (d *Deployer) checkOLMInstalled(ctx context.Context) error {
77-
// Check for OLM CRDs
78-
requiredCRDs := []string{
78+
requiredResources := []string{
7979
"catalogsources.operators.coreos.com",
8080
"subscriptions.operators.coreos.com",
8181
"installplans.operators.coreos.com",
8282
"clusterserviceversions.operators.coreos.com",
8383
}
8484

85-
for _, crd := range requiredCRDs {
86-
// TODO(ROX-34499): actually this is not the right way to check whether it's safe to create a resource of a given kind.
87-
// A CRD can be present, but still being loaded or end up not accepted by the API server.
88-
// Instead we should use the `kubectl api-resources` subcommand which exposes the status we're looking for.
89-
_, err := d.runKubectl(ctx, k8s.KubectlOptions{
90-
Args: []string{"get", "crd", crd},
91-
})
92-
if err != nil {
93-
return fmt.Errorf("OLM not installed: CRD %s not found. Please install OLM first", crd)
85+
result, err := d.runKubectl(ctx, k8s.KubectlOptions{
86+
Args: []string{"api-resources", "--api-group=operators.coreos.com", "-o", "name"},
87+
})
88+
if err != nil {
89+
if result.Stderr != "" {
90+
d.logger.Error("kubectl stderr:")
91+
for stderrLine := range strings.SplitSeq(result.Stderr, "\n") {
92+
d.logger.Errorf("stderr: %s", stderrLine)
93+
}
94+
}
95+
return fmt.Errorf("failed to query api-group operators.coreos.com: %w", err)
96+
}
97+
98+
available := make(map[string]bool)
99+
for line := range strings.SplitSeq(strings.TrimSpace(result.Stdout), "\n") {
100+
name := strings.TrimSpace(line)
101+
available[name] = true
102+
}
103+
104+
var missingResources []string
105+
for _, resource := range requiredResources {
106+
if !available[resource] {
107+
missingResources = append(missingResources, resource)
108+
}
109+
}
110+
if len(missingResources) > 0 {
111+
for _, resource := range missingResources {
112+
d.logger.Errorf("OLM resource not served by the API server: %s", resource)
94113
}
114+
return fmt.Errorf("OLM is not properly installed, %d required resource(s) missing", len(missingResources))
95115
}
96116

97117
d.logger.Success("✓ OLM detected in cluster")

0 commit comments

Comments
 (0)