Skip to content

Commit

Permalink
Make autoscalerRef optional
Browse files Browse the repository at this point in the history
- use anyOf as a workaround for the openAPI object validation not accepting empty values
- fix #23
  • Loading branch information
stefanprodan committed Jan 11, 2019
1 parent 1018540 commit aa2c28c
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 6 deletions.
4 changes: 3 additions & 1 deletion artifacts/flagger/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ spec:
name:
type: string
autoscalerRef:
type: object
anyOf:
- type: string
- type: object
required: ['apiVersion', 'kind', 'name']
properties:
apiVersion:
Expand Down
5 changes: 3 additions & 2 deletions charts/flagger/templates/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ spec:
name:
type: string
autoscalerRef:
type: object
anyOf:
- type: string
- type: object
required: ['apiVersion', 'kind', 'name']
properties:
apiVersion:
Expand Down Expand Up @@ -98,5 +100,4 @@ spec:
timeout:
type: string
pattern: "^[0-9]+(m|s)"

{{- end }}
3 changes: 2 additions & 1 deletion pkg/apis/flagger/v1alpha3/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
7 changes: 6 additions & 1 deletion pkg/apis/flagger/v1alpha3/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/controller/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit aa2c28c

Please sign in to comment.