Skip to content

Commit b5ae625

Browse files
authored
Add explicit skip-workload label for Websites (#609)
* Add explicit `skip-workload` label for `Websites` * `sample-generator`: allow skipping workload
1 parent f06bf79 commit b5ae625

File tree

5 files changed

+29
-9
lines changed

5 files changed

+29
-9
lines changed

webhosting-operator/cmd/samples-generator/main.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ import (
4343
var (
4444
scheme = runtime.NewScheme()
4545

46-
count int
47-
namespaces []string
46+
count int
47+
namespaces []string
48+
skipWorkload bool
4849
)
4950

5051
func init() {
@@ -70,6 +71,7 @@ func main() {
7071

7172
cmd.Flags().IntVarP(&count, "count", "c", count, "number of websites to generate per project")
7273
cmd.Flags().StringSliceVarP(&namespaces, "namespace", "n", namespaces, "project namespaces to generate websites in")
74+
cmd.Flags().BoolVar(&skipWorkload, "skip-workload", false, "don't run any actual workload for the generated websites")
7375

7476
if err := cmd.ExecuteContext(signals.SetupSignalHandler()); err != nil {
7577
fmt.Printf("Error generating samples: %v\n", err)
@@ -111,7 +113,7 @@ func generateSamples(ctx context.Context, c client.Client) error {
111113
}
112114

113115
for i := 0; i < websiteCount; i++ {
114-
if err := c.Create(ctx, &webhostingv1alpha1.Website{
116+
website := &webhostingv1alpha1.Website{
115117
ObjectMeta: metav1.ObjectMeta{
116118
Name: "sample-" + utils.RandomName(8),
117119
Namespace: project,
@@ -122,7 +124,13 @@ func generateSamples(ctx context.Context, c client.Client) error {
122124
Spec: webhostingv1alpha1.WebsiteSpec{
123125
Theme: utils.PickRandom(themes),
124126
},
125-
}); err != nil {
127+
}
128+
129+
if skipWorkload {
130+
website.Labels[webhostingv1alpha1.LabelKeySkipWorkload] = "true"
131+
}
132+
133+
if err := c.Create(ctx, website); err != nil {
126134
return err
127135
}
128136
}

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)