Skip to content

Commit

Permalink
Use fixed strings instead of knativeAutoscalingPrefix
Browse files Browse the repository at this point in the history
Use "autoscaling.knative.dev" instead of the const "knativeAutoscalingPrefix".

Signed-off-by: laminar <fangtian@kubesphere.io>
  • Loading branch information
tpiperatgod committed Jun 21, 2022
1 parent 96b63a4 commit 32e2f49
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 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 @@ -256,26 +255,22 @@ func (r *servingRun) createService(s *openfunction.Serving, cm map[string]string
case "min-scale", "minScale":
minScale = v
}
if _, exist := s.Spec.Annotations[fmt.Sprintf("%s/%s", knativeAutoscalingPrefix, k)]; !exist {
if _, exist := s.Spec.Annotations[fmt.Sprintf("autoscaling.knative.dev/%s", 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 _, exist := s.Spec.Annotations["autoscaling.knative.dev/max-scale"]; !exist && 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 _, exist := s.Spec.Annotations["autoscaling.knative.dev/min-scale"]; !exist && minScale != "" {
s.Spec.Annotations["autoscaling.knative.dev/minScale"] = minScale
s.Spec.Annotations["autoscaling.knative.dev/min-scale"] = minScale
}
}

Expand Down

0 comments on commit 32e2f49

Please sign in to comment.