Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions webhosting-operator/cmd/samples-generator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ import (
var (
scheme = runtime.NewScheme()

count int
namespaces []string
count int
namespaces []string
skipWorkload bool
)

func init() {
Expand All @@ -70,6 +71,7 @@ func main() {

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

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

for i := 0; i < websiteCount; i++ {
if err := c.Create(ctx, &webhostingv1alpha1.Website{
website := &webhostingv1alpha1.Website{
ObjectMeta: metav1.ObjectMeta{
Name: "sample-" + utils.RandomName(8),
Namespace: project,
Expand All @@ -122,7 +124,13 @@ func generateSamples(ctx context.Context, c client.Client) error {
Spec: webhostingv1alpha1.WebsiteSpec{
Theme: utils.PickRandom(themes),
},
}); err != nil {
}

if skipWorkload {
website.Labels[webhostingv1alpha1.LabelKeySkipWorkload] = "true"
}

if err := c.Create(ctx, website); err != nil {
return err
}
}
Expand Down
4 changes: 4 additions & 0 deletions webhosting-operator/pkg/apis/webhosting/v1alpha1/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ const (
LabelKeyProject = "webhosting.timebertt.dev/project"
// LabelValueProject is the label value for LabelKeyProject on Namespaces for identifying webhosting projects.
LabelValueProject = "true"

// LabelKeySkipWorkload is the label key on Websites for instructing webhosting-operator to skip any actual workload
// for the website. Any value is accepted as truthy.
LabelKeySkipWorkload = "skip-workload"
)

var (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ func (r *WebsiteReconciler) IngressForWebsite(serverName string, website *webhos

applyIngressConfigToIngress(r.Config.Ingress, ingress)

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

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

func isGeneratedByE2ETestOrExperiment(obj client.Object) bool {
return obj.GetLabels()["e2e-webhosting-operator"] != "" || obj.GetLabels()["generated-by"] == "experiment"
// skipWorkload returns true if the controller should not run any actual workload for this Website, e.g., for load tests
// or e2e tests.
func skipWorkload(website *webhostingv1alpha1.Website) bool {
_, ok := website.Labels[webhostingv1alpha1.LabelKeySkipWorkload]
return ok
}
2 changes: 2 additions & 0 deletions webhosting-operator/pkg/experiment/scenario/base/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ func (s *Scenario) AddToManager(mgr manager.Manager) error {
s.Labels = map[string]string{
"generated-by": "experiment",
"scenario": s.ScenarioName,

webhostingv1alpha1.LabelKeySkipWorkload: "true",
}

return mgr.Add(s)
Expand Down
5 changes: 4 additions & 1 deletion webhosting-operator/test/e2e/webhosting_operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,14 @@ func describeScaleController(text string, replicas int32) {
}

func newWebsite(name string) *webhostingv1alpha1.Website {
labels := maps.Clone(testRunLabels)
labels[webhostingv1alpha1.LabelKeySkipWorkload] = "true"

return &webhostingv1alpha1.Website{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace.Name,
Labels: maps.Clone(testRunLabels),
Labels: labels,
},
Spec: webhostingv1alpha1.WebsiteSpec{
Theme: theme.Name,
Expand Down
Loading