Use pointers for metadata because it is optional

and metadata parameter is nil on finalize.

in response to PR feedback
This commit is contained in:
Finn Herzfeld
2020-04-04 16:48:35 +03:00
committed by stefanprodan
parent b7441a7ce7
commit 2657e135b8
3 changed files with 24 additions and 8 deletions
+3 -3
View File
@@ -171,15 +171,15 @@ type CanaryService struct {
// Apex is metadata to add to the apex service
// +optional
Apex CustomMetadata `json:"apex,omitempty"`
Apex *CustomMetadata `json:"apex,omitempty"`
// Primary is the metadata to add to the primary service
// +optional
Primary CustomMetadata `json:"primary,omitempty"`
Primary *CustomMetadata `json:"primary,omitempty"`
// Canary is the metadata to add to the canary service
// +optional
Canary CustomMetadata `json:"canary,omitempty"`
Canary *CustomMetadata `json:"canary,omitempty"`
}
// CanaryAnalysis is used to describe how the analysis should be done
@@ -364,9 +364,21 @@ func (in *CanaryService) DeepCopyInto(out *CanaryService) {
*out = make([]string, len(*in))
copy(*out, *in)
}
in.Apex.DeepCopyInto(&out.Apex)
in.Primary.DeepCopyInto(&out.Primary)
in.Canary.DeepCopyInto(&out.Canary)
if in.Apex != nil {
in, out := &in.Apex, &out.Apex
*out = new(CustomMetadata)
(*in).DeepCopyInto(*out)
}
if in.Primary != nil {
in, out := &in.Primary, &out.Primary
*out = new(CustomMetadata)
(*in).DeepCopyInto(*out)
}
if in.Canary != nil {
in, out := &in.Canary, &out.Canary
*out = new(CustomMetadata)
(*in).DeepCopyInto(*out)
}
return
}
+6 -2
View File
@@ -69,7 +69,7 @@ func (c *KubernetesDefaultRouter) GetRoutes(_ *flaggerv1.Canary) (primaryRoute i
return 0, 0, nil
}
func (c *KubernetesDefaultRouter) reconcileService(canary *flaggerv1.Canary, name string, podSelector string, metadata flaggerv1.CustomMetadata) error {
func (c *KubernetesDefaultRouter) reconcileService(canary *flaggerv1.Canary, name string, podSelector string, metadata *flaggerv1.CustomMetadata) error {
portName := canary.Spec.Service.PortName
if portName == "" {
portName = "http"
@@ -113,6 +113,10 @@ func (c *KubernetesDefaultRouter) reconcileService(canary *flaggerv1.Canary, nam
svcSpec.Ports = append(svcSpec.Ports, cp)
}
if metadata == nil {
metadata = &flaggerv1.CustomMetadata{}
}
if metadata.Labels == nil {
metadata.Labels = make(map[string]string)
}
@@ -219,7 +223,7 @@ func (c *KubernetesDefaultRouter) Finalize(canary *flaggerv1.Canary) error {
return fmt.Errorf("service %s update error: %w", clone.Name, err)
}
} else {
err = c.reconcileService(canary, apexName, canary.Spec.TargetRef.Name, canary.Spec.Service.Apex)
err = c.reconcileService(canary, apexName, canary.Spec.TargetRef.Name, nil)
if err != nil {
return fmt.Errorf("reconcileService failed: %w", err)
}