Skip to content

Commit 7543175

Browse files
committed
Changed the skip healthchecks to a feature flag.
1 parent bcca1ea commit 7543175

File tree

7 files changed

+60
-35
lines changed

7 files changed

+60
-35
lines changed

config/manager/manager.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ spec:
4848
- --oidc-client-secret=$(OIDC_CLIENT_SECRET)
4949
- --oidc-issuer-url=$(OIDC_ISSUER_URL)
5050
- --only-public-clusters=$(ONLY_PUBLIC_CLUSTERS)
51+
- --skip-infrastructure-tests=$(SKIP_INFRASTRUCTURE_TESTS)
5152
env:
5253
- name: LOG_LEVEL
5354
# level 1 is debug, so when we want to raise the level we can
@@ -70,6 +71,8 @@ spec:
7071
value: "" # Default to empty - can be overridden in app-interface
7172
- name: ONLY_PUBLIC_CLUSTERS
7273
value: "false" # Default to false - can be overridden in app-interface
74+
- name: SKIP_INFRASTRUCTURE_TESTS
75+
value: "false" # Default to false - can be overridden in app-interface
7376
image: controller:latest
7477
name: manager
7578
securityContext:

controllers/hostedcontrolplane/healthcheck.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ const (
6363
// HCP namespace, and this process will be restarted. Additionally, should healthchecking need to be skipped for any reason, the annotation
6464
// "routemonitor.managed.openshift.io/successful-healthchecks" can be added-to/edited-on the configmap with a large number (ie - 999) to bypass
6565
// this functionality
66-
func (r *HostedControlPlaneReconciler) hcpReady(ctx context.Context, hostedcontrolplane *hypershiftv1beta1.HostedControlPlane) (bool, error) {
67-
// Skip health check for test HCPs (e.g., osde2e tests without real kube-apiserver)
68-
if _, osde2eTesting := hostedcontrolplane.Annotations["routemonitor.openshift.io/osde2e-testing"]; osde2eTesting {
66+
func (r *HostedControlPlaneReconciler) hcpReady(ctx context.Context, hostedcontrolplane *hypershiftv1beta1.HostedControlPlane, cfg RHOBSConfig) (bool, error) {
67+
// Skip health check for test environments (e.g., osde2e tests without real kube-apiserver)
68+
if cfg.SkipInfrastructureTests {
6969
return true, nil
7070
}
7171

@@ -232,9 +232,9 @@ func olderThan(obj metav1.Object, age time.Duration) bool {
232232
}
233233

234234
// isVpcEndpointReady checks if the VPC Endpoint associated with the HostedControlPlane is ready.
235-
func (r *HostedControlPlaneReconciler) isVpcEndpointReady(ctx context.Context, hostedcontrolplane *hypershiftv1beta1.HostedControlPlane) (bool, error) {
236-
// Skip VPC endpoint check for test HCPs (e.g., osde2e tests without real VPC infrastructure)
237-
if _, osde2eTesting := hostedcontrolplane.Annotations["routemonitor.openshift.io/osde2e-testing"]; osde2eTesting {
235+
func (r *HostedControlPlaneReconciler) isVpcEndpointReady(ctx context.Context, hostedcontrolplane *hypershiftv1beta1.HostedControlPlane, cfg RHOBSConfig) (bool, error) {
236+
// Skip VPC endpoint check for test environments (e.g., osde2e tests without real VPC infrastructure)
237+
if cfg.SkipInfrastructureTests {
238238
return true, nil
239239
}
240240

controllers/hostedcontrolplane/hostedcontrolplane.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ func (r *HostedControlPlaneReconciler) getRHOBSConfig(ctx context.Context) RHOBS
133133
if strings.TrimSpace(configMap.Data["only-public-clusters"]) == "true" {
134134
cfg.OnlyPublicClusters = true
135135
}
136+
if strings.TrimSpace(configMap.Data["skip-infrastructure-tests"]) == "true" {
137+
cfg.SkipInfrastructureTests = true
138+
}
136139

137140
return cfg
138141
}
@@ -260,7 +263,7 @@ func (r *HostedControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl.R
260263
}
261264

262265
// Ensure cluster is ready to be monitored before deploying any probing objects
263-
hcpReady, err := r.hcpReady(ctx, hostedcontrolplane)
266+
hcpReady, err := r.hcpReady(ctx, hostedcontrolplane, rhobsConfig)
264267
if err != nil {
265268
log.Error(err, "HCP readiness check failed")
266269
return utilreconcile.RequeueWith(fmt.Errorf("HCP readiness check failed: %v", err))
@@ -270,7 +273,7 @@ func (r *HostedControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl.R
270273
return utilreconcile.RequeueAfter(healthcheckIntervalSeconds * time.Second), nil
271274
}
272275

273-
vpcEndpointReady, err := r.isVpcEndpointReady(ctx, hostedcontrolplane)
276+
vpcEndpointReady, err := r.isVpcEndpointReady(ctx, hostedcontrolplane, rhobsConfig)
274277
if err != nil {
275278
log.Error(err, "VPC Endpoint check failed")
276279
return utilreconcile.RequeueWith(err)
@@ -282,7 +285,7 @@ func (r *HostedControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl.R
282285

283286
// Cluster ready - deploy kube-apiserver monitoring objects
284287
log.Info("Deploying internal monitoring objects")
285-
err = r.deployInternalMonitoringObjects(ctx, log, hostedcontrolplane)
288+
err = r.deployInternalMonitoringObjects(ctx, log, hostedcontrolplane, rhobsConfig)
286289
if err != nil {
287290
log.Error(err, "failed to deploy internal monitoring components")
288291
return utilreconcile.RequeueWith(err)
@@ -321,9 +324,9 @@ func (r *HostedControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl.R
321324
}
322325

323326
// deployInternalMonitoringObjects creates or updates the objects needed to monitor the kube-apiserver using cluster-internal routes
324-
func (r *HostedControlPlaneReconciler) deployInternalMonitoringObjects(ctx context.Context, log logr.Logger, hostedcontrolplane *hypershiftv1beta1.HostedControlPlane) error {
325-
// Skip internal monitoring for test HCPs (e.g., osde2e tests without real kube-apiserver infrastructure)
326-
if _, osde2eTesting := hostedcontrolplane.Annotations["routemonitor.openshift.io/osde2e-testing"]; osde2eTesting {
327+
func (r *HostedControlPlaneReconciler) deployInternalMonitoringObjects(ctx context.Context, log logr.Logger, hostedcontrolplane *hypershiftv1beta1.HostedControlPlane, cfg RHOBSConfig) error {
328+
// Skip internal monitoring for test environments (e.g., osde2e tests without real kube-apiserver infrastructure)
329+
if cfg.SkipInfrastructureTests {
327330
return nil
328331
}
329332

controllers/hostedcontrolplane/hostedcontrolplane_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ func TestHostedControlPlaneReconciler_deployInternalMonitoringObjects(t *testing
571571
for _, tt := range tests {
572572
t.Run(tt.name, func(t *testing.T) {
573573
r := newTestReconciler(t, tt.objs...)
574-
err := r.deployInternalMonitoringObjects(tt.args.ctx, tt.args.log, tt.args.hostedcontrolplane)
574+
err := r.deployInternalMonitoringObjects(tt.args.ctx, tt.args.log, tt.args.hostedcontrolplane, RHOBSConfig{})
575575
passed, reason := tt.eval(err, r)
576576
if !passed {
577577
t.Errorf("HostedControlPlaneReconciler.deployInternalMonitoringObjects() did not pass due to = %s", reason)
@@ -827,7 +827,7 @@ func TestIsVpcEndpointReady(t *testing.T) {
827827
}
828828

829829
// Test the function
830-
result, err := r.isVpcEndpointReady(context.Background(), hcp)
830+
result, err := r.isVpcEndpointReady(context.Background(), hcp, RHOBSConfig{})
831831

832832
// Validate the results
833833
if result != tt.expectedResult {

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ require (
1414
github.com/openshift/api v0.0.0-20250409155250-8fcc4e71758a
1515
github.com/openshift/aws-vpce-operator v0.0.0-20241211114942-1daecf2e4364
1616
github.com/openshift/hypershift/api v0.0.0-20241204143212-857ccab4fd7c
17-
github.com/openshift/osde2e v0.0.0-20260202205050-a418c410e9bc
17+
github.com/openshift/osde2e v0.0.0-20260209164730-1a4541c8e2b1
1818
github.com/openshift/osde2e-common v0.0.0-20260126213857-862206787cf9
1919
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.64.0
2020
github.com/prometheus/common v0.67.5

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,8 @@ github.com/openshift/aws-vpce-operator v0.0.0-20241211114942-1daecf2e4364 h1:wrR
230230
github.com/openshift/aws-vpce-operator v0.0.0-20241211114942-1daecf2e4364/go.mod h1:+/t18O2NwRYEzWbi76OImNMivJXi6bbFVG3ODGeQjMk=
231231
github.com/openshift/hypershift/api v0.0.0-20241204143212-857ccab4fd7c h1:NBH3no8kaW7Hem/mf/0lIfZZEIeaNTwo7XfTqUm2cJc=
232232
github.com/openshift/hypershift/api v0.0.0-20241204143212-857ccab4fd7c/go.mod h1:K1e56UPfFQaO8BYXbVS1TbNqb6rmPo+fc6Jxjv+w0Xo=
233-
github.com/openshift/osde2e v0.0.0-20260202205050-a418c410e9bc h1:W6qCZPI/2f64vRbDbUH0wrVzXTcjV5UBBTrIfD/giO8=
234-
github.com/openshift/osde2e v0.0.0-20260202205050-a418c410e9bc/go.mod h1:VW4cnPpR92sfzwuhzPWatXYAo7/ZgyjYhCDPPONjUfk=
233+
github.com/openshift/osde2e v0.0.0-20260209164730-1a4541c8e2b1 h1:2tqxJRv06Psmb1r9CYHEhjK0FW/uZmH6ZorQn9wJHT4=
234+
github.com/openshift/osde2e v0.0.0-20260209164730-1a4541c8e2b1/go.mod h1:VW4cnPpR92sfzwuhzPWatXYAo7/ZgyjYhCDPPONjUfk=
235235
github.com/openshift/osde2e-common v0.0.0-20260126213857-862206787cf9 h1:oUYQpPED774xWW41aRfrhvPSEcIN3FR6XeePOVqcljk=
236236
github.com/openshift/osde2e-common v0.0.0-20260126213857-862206787cf9/go.mod h1:nMeOffePy+qdcCXuwTw5YcMMn/cTfjYQf7KRLjhKweo=
237237
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=

main.go

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ func main() {
9494
var oidcClientSecret string
9595
var oidcIssuerURL string
9696
var onlyPublicClusters bool
97+
var skipInfrastructureTests bool
9798

9899
flag.StringVar(&blackboxExporterImage, "blackbox-image", "quay.io/prometheus/blackbox-exporter@sha256:b04a9fef4fa086a02fc7fcd8dcdbc4b7b35cc30cdee860fdc6a19dd8b208d63e", "The image that will be used for the blackbox-exporter deployment")
99100
flag.StringVar(&blackboxExporterNamespace, "blackbox-namespace", config.OperatorNamespace, "Blackbox-exporter deployment will reside on this Namespace")
@@ -103,6 +104,7 @@ func main() {
103104
flag.StringVar(&oidcClientSecret, "oidc-client-secret", "", "OIDC client secret for RHOBS API authentication. When empty, no OIDC authentication is used.")
104105
flag.StringVar(&oidcIssuerURL, "oidc-issuer-url", "", "OIDC issuer URL for RHOBS API authentication. When empty, no OIDC authentication is used.")
105106
flag.BoolVar(&onlyPublicClusters, "only-public-clusters", false, "When true, only create RHOBS probes for public (non-private) HostedClusters. Defaults to false (process all clusters).")
107+
flag.BoolVar(&skipInfrastructureTests, "skip-infrastructure-tests", false, "When true, skip infrastructure health checks (HCP ready, VPC endpoint ready) for test environments. Defaults to false.")
106108

107109
opts := zap.Options{}
108110
opts.BindFlags(flag.CommandLine)
@@ -167,6 +169,14 @@ func main() {
167169
flagParams = append(flagParams, "only-public-clusters")
168170
}
169171

172+
if configData.SkipInfrastructureTests {
173+
setupLog.V(1).Info("Using skip-infrastructure-tests from ConfigMap", "skipInfrastructureTests", configData.SkipInfrastructureTests)
174+
skipInfrastructureTests = configData.SkipInfrastructureTests
175+
configMapParams = append(configMapParams, "skip-infrastructure-tests")
176+
} else {
177+
flagParams = append(flagParams, "skip-infrastructure-tests")
178+
}
179+
170180
// Summarize configuration sources
171181
if len(configMapParams) > 0 && len(flagParams) > 0 {
172182
setupLog.Info("Using mixed configuration sources",
@@ -269,12 +279,13 @@ func main() {
269279

270280
if enableHCP {
271281
rhobsConfig := hostedcontrolplane.RHOBSConfig{
272-
ProbeAPIURL: probeAPIURL,
273-
Tenant: probeTenant,
274-
OIDCClientID: oidcClientID,
275-
OIDCClientSecret: oidcClientSecret,
276-
OIDCIssuerURL: oidcIssuerURL,
277-
OnlyPublicClusters: onlyPublicClusters,
282+
ProbeAPIURL: probeAPIURL,
283+
Tenant: probeTenant,
284+
OIDCClientID: oidcClientID,
285+
OIDCClientSecret: oidcClientSecret,
286+
OIDCIssuerURL: oidcIssuerURL,
287+
OnlyPublicClusters: onlyPublicClusters,
288+
SkipInfrastructureTests: skipInfrastructureTests,
278289
}
279290
hostedControlPlaneReconciler := hostedcontrolplane.NewHostedControlPlaneReconciler(mgr, rhobsConfig)
280291
if err = hostedControlPlaneReconciler.SetupWithManager(mgr); err != nil {
@@ -326,12 +337,13 @@ func shouldEnableHCP() (bool, error) {
326337

327338
// OperatorConfig holds configuration values from ConfigMap
328339
type OperatorConfig struct {
329-
ProbeAPIURL string
330-
ProbeTenant string
331-
OIDCClientID string
332-
OIDCClientSecret string
333-
OIDCIssuerURL string
334-
OnlyPublicClusters bool
340+
ProbeAPIURL string
341+
ProbeTenant string
342+
OIDCClientID string
343+
OIDCClientSecret string
344+
OIDCIssuerURL string
345+
OnlyPublicClusters bool
346+
SkipInfrastructureTests bool
335347
}
336348

337349
// getConfigFromConfigMap reads configuration from the route-monitor-operator-config ConfigMap
@@ -363,12 +375,13 @@ func getConfigFromConfigMap() (*OperatorConfig, error) {
363375

364376
// Extract configuration values, trimming whitespace
365377
cfg := &OperatorConfig{
366-
ProbeAPIURL: strings.TrimSpace(configMap.Data["probe-api-url"]),
367-
ProbeTenant: strings.TrimSpace(configMap.Data["probe-tenant"]),
368-
OIDCClientID: strings.TrimSpace(configMap.Data["oidc-client-id"]),
369-
OIDCClientSecret: strings.TrimSpace(configMap.Data["oidc-client-secret"]),
370-
OIDCIssuerURL: strings.TrimSpace(configMap.Data["oidc-issuer-url"]),
371-
OnlyPublicClusters: strings.TrimSpace(configMap.Data["only-public-clusters"]) == "true",
378+
ProbeAPIURL: strings.TrimSpace(configMap.Data["probe-api-url"]),
379+
ProbeTenant: strings.TrimSpace(configMap.Data["probe-tenant"]),
380+
OIDCClientID: strings.TrimSpace(configMap.Data["oidc-client-id"]),
381+
OIDCClientSecret: strings.TrimSpace(configMap.Data["oidc-client-secret"]),
382+
OIDCIssuerURL: strings.TrimSpace(configMap.Data["oidc-issuer-url"]),
383+
OnlyPublicClusters: strings.TrimSpace(configMap.Data["only-public-clusters"]) == "true",
384+
SkipInfrastructureTests: strings.TrimSpace(configMap.Data["skip-infrastructure-tests"]) == "true",
372385
}
373386

374387
// Log detailed information about what was found in the ConfigMap
@@ -411,6 +424,12 @@ func getConfigFromConfigMap() (*OperatorConfig, error) {
411424
missingParams = append(missingParams, "only-public-clusters")
412425
}
413426

427+
if configMap.Data["skip-infrastructure-tests"] != "" {
428+
foundParams = append(foundParams, "skip-infrastructure-tests")
429+
} else {
430+
missingParams = append(missingParams, "skip-infrastructure-tests")
431+
}
432+
414433
setupLog.Info("ConfigMap found and processed",
415434
"configmap", configMapName,
416435
"namespace", config.OperatorNamespace,

0 commit comments

Comments
 (0)