Make autoscalerRef optional

- use anyOf as a workaround for the openAPI object validation not accepting empty values
- fix #23
This commit is contained in:
stefanprodan
2019-01-11 13:42:32 +02:00
parent 10185407f6
commit aa2c28c733
5 changed files with 15 additions and 6 deletions

View File

@@ -42,7 +42,9 @@ spec:
name:
type: string
autoscalerRef:
type: object
anyOf:
- type: string
- type: object
required: ['apiVersion', 'kind', 'name']
properties:
apiVersion:

View File

@@ -43,7 +43,9 @@ spec:
name:
type: string
autoscalerRef:
type: object
anyOf:
- type: string
- type: object
required: ['apiVersion', 'kind', 'name']
properties:
apiVersion:
@@ -98,5 +100,4 @@ spec:
timeout:
type: string
pattern: "^[0-9]+(m|s)"
{{- end }}

View File

@@ -46,7 +46,8 @@ type CanarySpec struct {
TargetRef hpav1.CrossVersionObjectReference `json:"targetRef"`
// reference to autoscaling resource
AutoscalerRef hpav1.CrossVersionObjectReference `json:"autoscalerRef"`
// +optional
AutoscalerRef *hpav1.CrossVersionObjectReference `json:"autoscalerRef,omitempty"`
// virtual service spec
Service CanaryService `json:"service"`

View File

@@ -21,6 +21,7 @@ limitations under the License.
package v1alpha3
import (
v1 "k8s.io/api/autoscaling/v1"
runtime "k8s.io/apimachinery/pkg/runtime"
)
@@ -159,7 +160,11 @@ func (in *CanaryService) DeepCopy() *CanaryService {
func (in *CanarySpec) DeepCopyInto(out *CanarySpec) {
*out = *in
out.TargetRef = in.TargetRef
out.AutoscalerRef = in.AutoscalerRef
if in.AutoscalerRef != nil {
in, out := &in.AutoscalerRef, &out.AutoscalerRef
*out = new(v1.CrossVersionObjectReference)
**out = **in
}
in.Service.DeepCopyInto(&out.Service)
in.CanaryAnalysis.DeepCopyInto(&out.CanaryAnalysis)
if in.ProgressDeadlineSeconds != nil {

View File

@@ -231,7 +231,7 @@ func (c *CanaryDeployer) Sync(cd *flaggerv1.Canary) error {
}
}
if cd.Spec.AutoscalerRef.Kind == "HorizontalPodAutoscaler" {
if cd.Spec.AutoscalerRef != nil && cd.Spec.AutoscalerRef.Kind == "HorizontalPodAutoscaler" {
if err := c.createPrimaryHpa(cd); err != nil {
return fmt.Errorf("creating hpa %s.%s failed: %v", primaryName, cd.Namespace, err)
}