Skip to content

Commit

Permalink
Make SecretRef pointer again (#540)
Browse files Browse the repository at this point in the history
  • Loading branch information
tamalsaha committed Dec 13, 2017
1 parent 94c1c57 commit c214642
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 13 deletions.
2 changes: 1 addition & 1 deletion apis/voyager/ingress.go
Expand Up @@ -110,7 +110,7 @@ type IngressTLS struct {
SecretName string `json:"secretName,omitempty"`

// SecretRef to used tls termination.
SecretRef apiv1.ObjectReference `json:"secretRef,omitempty"`
SecretRef *apiv1.ObjectReference `json:"secretRef,omitempty"`
}

// IngressStatus describe the current state of the Ingress.
Expand Down
6 changes: 3 additions & 3 deletions apis/voyager/v1beta1/diff.go
Expand Up @@ -56,9 +56,9 @@ func (r Ingress) HasChanged(o Ingress) (bool, error) {
return !reflect.DeepEqual(ra, oa), nil
}

func (r Ingress) FindTLSSecret(h string) (apiv1.ObjectReference, bool) {
func (r Ingress) FindTLSSecret(h string) (*apiv1.ObjectReference, bool) {
if h == "" {
return apiv1.ObjectReference{}, false
return nil, false
}
for _, tls := range r.Spec.TLS {
for _, host := range tls.Hosts {
Expand All @@ -67,7 +67,7 @@ func (r Ingress) FindTLSSecret(h string) (apiv1.ObjectReference, bool) {
}
}
}
return apiv1.ObjectReference{}, false
return nil, false
}

func (r Ingress) IsPortChanged(o Ingress, cloudProvider string) bool {
Expand Down
2 changes: 1 addition & 1 deletion apis/voyager/v1beta1/ingress.go
Expand Up @@ -111,7 +111,7 @@ type IngressTLS struct {
SecretName string `json:"secretName,omitempty"`

// SecretRef to used tls termination.
SecretRef apiv1.ObjectReference `json:"secretRef,omitempty"`
SecretRef *apiv1.ObjectReference `json:"secretRef,omitempty"`
}

// IngressStatus describe the current state of the Ingress.
Expand Down
16 changes: 10 additions & 6 deletions apis/voyager/v1beta1/validator.go
Expand Up @@ -5,10 +5,10 @@ import (
"strconv"
"strings"

"github.com/appscode/go/reflect"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/validation"
apiv1 "k8s.io/client-go/pkg/api/v1"
)

type indices struct {
Expand Down Expand Up @@ -41,16 +41,20 @@ func (r *Ingress) IsValid(cloudProvider string) error {
}
for ti, tls := range r.Spec.TLS {
if tls.SecretName != "" {
if !reflect.IsZero(tls.SecretRef) &&
if tls.SecretRef != nil &&
!(tls.SecretRef.Name == tls.SecretName &&
(tls.SecretRef.Namespace == "" || tls.SecretRef.Namespace == r.Namespace) &&
(tls.SecretRef.Kind == "" || tls.SecretRef.Kind == "Secret")) {
return fmt.Errorf("spec.tls[%d] specifies different secret name and secret ref", ti)
}
tls.SecretRef.APIVersion = "v1"
tls.SecretRef.Kind = "Secret"
tls.SecretRef.Name = tls.SecretName
} else if reflect.IsZero(tls.SecretRef) {
if r.Spec.TLS[ti].SecretRef == nil {
r.Spec.TLS[ti].SecretRef = &apiv1.ObjectReference{
APIVersion: "v1",
Kind: "Secret",
Name: tls.SecretName,
}
}
} else if tls.SecretRef == nil {
return fmt.Errorf("spec.tls[%d] specifies no secret name and secret ref", ti)
} else {
if tls.SecretRef.Kind != "" && sets.NewString("Secret", "Certificate").Has(tls.SecretRef.Kind) {
Expand Down
4 changes: 2 additions & 2 deletions apis/voyager/v1beta1/zz_generated.conversion.go
Expand Up @@ -722,7 +722,7 @@ func Convert_voyager_IngressStatus_To_v1beta1_IngressStatus(in *voyager.IngressS
func autoConvert_v1beta1_IngressTLS_To_voyager_IngressTLS(in *IngressTLS, out *voyager.IngressTLS, s conversion.Scope) error {
out.Hosts = *(*[]string)(unsafe.Pointer(&in.Hosts))
out.SecretName = in.SecretName
out.SecretRef = in.SecretRef
out.SecretRef = (*api_v1.ObjectReference)(unsafe.Pointer(in.SecretRef))
return nil
}

Expand All @@ -734,7 +734,7 @@ func Convert_v1beta1_IngressTLS_To_voyager_IngressTLS(in *IngressTLS, out *voyag
func autoConvert_voyager_IngressTLS_To_v1beta1_IngressTLS(in *voyager.IngressTLS, out *IngressTLS, s conversion.Scope) error {
out.Hosts = *(*[]string)(unsafe.Pointer(&in.Hosts))
out.SecretName = in.SecretName
out.SecretRef = in.SecretRef
out.SecretRef = (*api_v1.ObjectReference)(unsafe.Pointer(in.SecretRef))
return nil
}

Expand Down
5 changes: 5 additions & 0 deletions apis/voyager/v1beta1/zz_generated.deepcopy.go
Expand Up @@ -566,6 +566,11 @@ func DeepCopy_v1beta1_IngressTLS(in interface{}, out interface{}, c *conversion.
*out = make([]string, len(*in))
copy(*out, *in)
}
if in.SecretRef != nil {
in, out := &in.SecretRef, &out.SecretRef
*out = new(api_v1.ObjectReference)
**out = **in
}
return nil
}
}
Expand Down
5 changes: 5 additions & 0 deletions apis/voyager/zz_generated.deepcopy.go
Expand Up @@ -533,6 +533,11 @@ func DeepCopy_voyager_IngressTLS(in interface{}, out interface{}, c *conversion.
*out = make([]string, len(*in))
copy(*out, *in)
}
if in.SecretRef != nil {
in, out := &in.SecretRef, &out.SecretRef
*out = new(api_v1.ObjectReference)
**out = **in
}
return nil
}
}
Expand Down

0 comments on commit c214642

Please sign in to comment.