Skip to content

Commit 753012d

Browse files
committed
Add explicit skip-workload label for Websites
1 parent f06bf79 commit 753012d

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

webhosting-operator/pkg/apis/webhosting/v1alpha1/constants.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ const (
2929
LabelKeyProject = "webhosting.timebertt.dev/project"
3030
// LabelValueProject is the label value for LabelKeyProject on Namespaces for identifying webhosting projects.
3131
LabelValueProject = "true"
32+
33+
// LabelKeySkipWorkload is the label key on Websites for instructing webhosting-operator to skip any actual workload
34+
// for the website. Any value is accepted as truthy.
35+
LabelKeySkipWorkload = "skip-workload"
3236
)
3337

3438
var (

webhosting-operator/pkg/controllers/webhosting/website_controller.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ func (r *WebsiteReconciler) IngressForWebsite(serverName string, website *webhos
304304

305305
applyIngressConfigToIngress(r.Config.Ingress, ingress)
306306

307-
if isGeneratedByE2ETestOrExperiment(website) {
307+
if skipWorkload(website) {
308308
// don't actually expose website ingresses in load tests
309309
// use fake ingress class to prevent overloading ingress controller (this is not what we want to load test)
310310
ingress.Spec.IngressClassName = ptr.To("fake")
@@ -424,7 +424,7 @@ func (r *WebsiteReconciler) DeploymentForWebsite(serverName string, website *web
424424
},
425425
}
426426

427-
if isGeneratedByE2ETestOrExperiment(website) {
427+
if skipWorkload(website) {
428428
// don't actually run website pods in load tests
429429
// otherwise, we would need an immense amount of compute power for running dummy websites
430430
deployment.Spec.Replicas = ptr.To[int32](0)
@@ -611,6 +611,9 @@ var ConfigMapDataChanged = predicate.Funcs{
611611
},
612612
}
613613

614-
func isGeneratedByE2ETestOrExperiment(obj client.Object) bool {
615-
return obj.GetLabels()["e2e-webhosting-operator"] != "" || obj.GetLabels()["generated-by"] == "experiment"
614+
// skipWorkload returns true if the controller should not run any actual workload for this Website, e.g., for load tests
615+
// or e2e tests.
616+
func skipWorkload(website *webhostingv1alpha1.Website) bool {
617+
_, ok := website.Labels[webhostingv1alpha1.LabelKeySkipWorkload]
618+
return ok
616619
}

webhosting-operator/pkg/experiment/scenario/base/base.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ func (s *Scenario) AddToManager(mgr manager.Manager) error {
8080
s.Labels = map[string]string{
8181
"generated-by": "experiment",
8282
"scenario": s.ScenarioName,
83+
84+
webhostingv1alpha1.LabelKeySkipWorkload: "true",
8385
}
8486

8587
return mgr.Add(s)

webhosting-operator/test/e2e/webhosting_operator_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,14 @@ func describeScaleController(text string, replicas int32) {
128128
}
129129

130130
func newWebsite(name string) *webhostingv1alpha1.Website {
131+
labels := maps.Clone(testRunLabels)
132+
labels[webhostingv1alpha1.LabelKeySkipWorkload] = "true"
133+
131134
return &webhostingv1alpha1.Website{
132135
ObjectMeta: metav1.ObjectMeta{
133136
Name: name,
134137
Namespace: namespace.Name,
135-
Labels: maps.Clone(testRunLabels),
138+
Labels: labels,
136139
},
137140
Spec: webhostingv1alpha1.WebsiteSpec{
138141
Theme: theme.Name,

0 commit comments

Comments
 (0)