Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use fixed strings instead of knativeAutoscalingPrefix #311

Merged
merged 1 commit into from
Jun 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 16 additions & 21 deletions pkg/core/serving/knative/servingrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import (
const (
knativeService = "serving.knative.dev/service"
componentName = "Knative/component"
knativeAutoscalingPrefix = "autoscaling.knative.dev"
)

type servingRun struct {
Expand Down Expand Up @@ -234,14 +233,19 @@ func (r *servingRun) createService(s *openfunction.Serving, cm map[string]string
labels = util.AppendLabels(s.Spec.Labels, labels)

// Handle the scale options, which have the following priority relationship:
// Annotations["autoscaling.knative.dev/max-scale" ("autoscaling.knative.dev/min-scale")] >
// ScaleOptions.Knative["max-scale" ("min-scale")] >
// ScaleOptions.Knative["autoscaling.knative.dev/max-scale" ("autoscaling.knative.dev/min-scale")] >
// ScaleOptions.maxScale (minScale) >
// Annotations["autoscaling.knative.dev/max-scale" ("autoscaling.knative.dev/min-scale")] >
// And in Knative Serving v1.1, the scale bounds' name were changed from "maxScale" ("minScale") to "max-scale" ("min-scale"),
// we need to support both of these layouts.
if s.Spec.ScaleOptions != nil {
maxScale := ""
minScale := ""

if s.Spec.Annotations == nil {
s.Spec.Annotations = map[string]string{}
}

if s.Spec.ScaleOptions.MaxReplicas != nil {
maxScale = strconv.Itoa(int(*s.Spec.ScaleOptions.MaxReplicas))
}
Expand All @@ -251,31 +255,22 @@ func (r *servingRun) createService(s *openfunction.Serving, cm map[string]string
if s.Spec.ScaleOptions.Knative != nil {
for k, v := range *s.Spec.ScaleOptions.Knative {
switch k {
case "max-scale", "maxScale":
case "autoscaling.knative.dev/max-scale", "autoscaling.knative.dev/maxScale":
maxScale = v
case "min-scale", "minScale":
case "autoscaling.knative.dev/min-scale", "autoscaling.knative.dev/minScale":
minScale = v
}
if _, exist := s.Spec.Annotations[fmt.Sprintf("%s/%s", knativeAutoscalingPrefix, k)]; !exist {
s.Spec.Annotations[k] = v
}
}
}
maxScaleAnnotationOld := fmt.Sprintf("%s/%s", knativeAutoscalingPrefix, "maxScale")
maxScaleAnnotation := fmt.Sprintf("%s/%s", knativeAutoscalingPrefix, "max-scale")
minScaleAnnotationOld := fmt.Sprintf("%s/%s", knativeAutoscalingPrefix, "minScale")
minScaleAnnotation := fmt.Sprintf("%s/%s", knativeAutoscalingPrefix, "min-scale")

if s.Spec.Annotations == nil {
s.Spec.Annotations = map[string]string{}
}
if _, exist := s.Spec.Annotations[maxScaleAnnotation]; !exist && maxScale != "" {
s.Spec.Annotations[maxScaleAnnotationOld] = maxScale
s.Spec.Annotations[maxScaleAnnotation] = maxScale
if maxScale != "" {
s.Spec.Annotations["autoscaling.knative.dev/maxScale"] = maxScale
s.Spec.Annotations["autoscaling.knative.dev/max-scale"] = maxScale
}
if _, exist := s.Spec.Annotations[minScaleAnnotation]; !exist && minScale != "" {
s.Spec.Annotations[minScaleAnnotationOld] = minScale
s.Spec.Annotations[minScaleAnnotation] = minScale

if minScale != "" {
s.Spec.Annotations["autoscaling.knative.dev/minScale"] = minScale
s.Spec.Annotations["autoscaling.knative.dev/min-scale"] = minScale
}
}

Expand Down