From 561de19e49018f482e6a0f17fa64f2777a68e3a5 Mon Sep 17 00:00:00 2001 From: EdgeJ <5093048+EdgeJ@users.noreply.github.com> Date: Mon, 28 Mar 2022 11:18:10 -0400 Subject: [PATCH] Insert refs into existing certificates APIs Signed-off-by: EdgeJ <5093048+EdgeJ@users.noreply.github.com> --- apis/elbv2/v1alpha1/custom_types.go | 30 ++++++--- apis/elbv2/v1alpha1/referencers.go | 26 ++++---- apis/elbv2/v1alpha1/zz_generated.deepcopy.go | 54 ++++++++++++---- examples/elbv2/listener.yaml | 5 +- .../elbv2.aws.crossplane.io_listeners.yaml | 64 +++++++++++-------- pkg/controller/elbv2/listener/setup.go | 10 +-- 6 files changed, 123 insertions(+), 66 deletions(-) diff --git a/apis/elbv2/v1alpha1/custom_types.go b/apis/elbv2/v1alpha1/custom_types.go index 9d0b20aac3..ca4cccd879 100644 --- a/apis/elbv2/v1alpha1/custom_types.go +++ b/apis/elbv2/v1alpha1/custom_types.go @@ -2,6 +2,24 @@ package v1alpha1 import xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1" +// CustomCertificate includes custom fields about certificates. +type CustomCertificate struct { + // [HTTPS and TLS listeners] The default certificate for the listener. + // +optional + CertificateARN *string `json:"certificateARN,omitempty"` + + // Reference to Certificates for Certificate ARN + // +optional + CertificateARNRef *xpv1.Reference `json:"certificateARNRef,omitempty"` + + // Selector for references to Certificate for CertificateArn + // +optional + CertificateARNSelector *xpv1.Selector `json:"certificateARNSelector,omitempty"` + + // +optional + IsDefault bool `json:"isDefault,omitempty"` +} + // CustomTargetGroupTuple includes custom fields about target groups. // Only used with ForwardActionConfig to route to multiple target groups. type CustomTargetGroupTuple struct { // inject refs and selectors into TargetGroupTuple @@ -91,15 +109,11 @@ type CustomAction struct { // CustomListenerParameters includes the custom fields of Listener. type CustomListenerParameters struct { - // [HTTPS and TLS listeners] The default certificate for the listener. + // [HTTPS and TLS listeners] The default certificate + // for the listener. You must provide exactly one certificate. + // Set CertificateArn to the certificate ARN but do not set IsDefault. // +optional - CertificateARN *string `json:"certificateArn,omitempty"` - - // Reference to Certificates for Certificate ARN - CertificateARNRef *xpv1.Reference `json:"certificateArnRef,omitempty"` - - // Selector for references to Certificate for CertificateArn - CertificateARNSelector *xpv1.Selector `json:"certificateArnSelector,omitempty"` + Certificates []*CustomCertificate `json:"certificates,omitempty"` // The actions for the default rule. // +kubebuilder:validation:Required diff --git a/apis/elbv2/v1alpha1/referencers.go b/apis/elbv2/v1alpha1/referencers.go index ed32f0dbf0..bd20b79822 100644 --- a/apis/elbv2/v1alpha1/referencers.go +++ b/apis/elbv2/v1alpha1/referencers.go @@ -30,21 +30,23 @@ func (mg *Listener) ResolveReferences(ctx context.Context, c client.Reader) erro r := reference.NewAPIResolver(c, mg) // resolve certificate ARN reference - rsp, err := r.Resolve(ctx, reference.ResolutionRequest{ - CurrentValue: reference.FromPtrValue(mg.Spec.ForProvider.CertificateARN), - Reference: mg.Spec.ForProvider.CertificateARNRef, - Selector: mg.Spec.ForProvider.CertificateARNSelector, - To: reference.To{Managed: &acm.Certificate{}, List: &acm.CertificateList{}}, - Extract: reference.ExternalName(), - }) - if err != nil { - return errors.Wrap(err, "spec.forProvider.certificateArn") + for i := range mg.Spec.ForProvider.Certificates { + rsp, err := r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.ForProvider.Certificates[i].CertificateARN), + Reference: mg.Spec.ForProvider.Certificates[i].CertificateARNRef, + Selector: mg.Spec.ForProvider.Certificates[i].CertificateARNSelector, + To: reference.To{Managed: &acm.Certificate{}, List: &acm.CertificateList{}}, + Extract: reference.ExternalName(), + }) + if err != nil { + return errors.Wrap(err, "spec.forProvider.certificateArn") + } + mg.Spec.ForProvider.Certificates[i].CertificateARN = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.ForProvider.Certificates[i].CertificateARNRef = rsp.ResolvedReference } - mg.Spec.ForProvider.CertificateARN = reference.ToPtrValue(rsp.ResolvedValue) - mg.Spec.ForProvider.CertificateARNRef = rsp.ResolvedReference // resolve loadbalancer ARN reference - rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + rsp, err := r.Resolve(ctx, reference.ResolutionRequest{ CurrentValue: reference.FromPtrValue(mg.Spec.ForProvider.LoadBalancerARN), Reference: mg.Spec.ForProvider.LoadBalancerARNRef, Selector: mg.Spec.ForProvider.LoadBalancerARNSelector, diff --git a/apis/elbv2/v1alpha1/zz_generated.deepcopy.go b/apis/elbv2/v1alpha1/zz_generated.deepcopy.go index 2147c2123a..72c4d08093 100644 --- a/apis/elbv2/v1alpha1/zz_generated.deepcopy.go +++ b/apis/elbv2/v1alpha1/zz_generated.deepcopy.go @@ -362,6 +362,36 @@ func (in *CustomAction) DeepCopy() *CustomAction { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CustomCertificate) DeepCopyInto(out *CustomCertificate) { + *out = *in + if in.CertificateARN != nil { + in, out := &in.CertificateARN, &out.CertificateARN + *out = new(string) + **out = **in + } + if in.CertificateARNRef != nil { + in, out := &in.CertificateARNRef, &out.CertificateARNRef + *out = new(v1.Reference) + **out = **in + } + if in.CertificateARNSelector != nil { + in, out := &in.CertificateARNSelector, &out.CertificateARNSelector + *out = new(v1.Selector) + (*in).DeepCopyInto(*out) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CustomCertificate. +func (in *CustomCertificate) DeepCopy() *CustomCertificate { + if in == nil { + return nil + } + out := new(CustomCertificate) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *CustomForwardActionConfig) DeepCopyInto(out *CustomForwardActionConfig) { *out = *in @@ -396,20 +426,16 @@ func (in *CustomForwardActionConfig) DeepCopy() *CustomForwardActionConfig { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *CustomListenerParameters) DeepCopyInto(out *CustomListenerParameters) { *out = *in - if in.CertificateARN != nil { - in, out := &in.CertificateARN, &out.CertificateARN - *out = new(string) - **out = **in - } - if in.CertificateARNRef != nil { - in, out := &in.CertificateARNRef, &out.CertificateARNRef - *out = new(v1.Reference) - **out = **in - } - if in.CertificateARNSelector != nil { - in, out := &in.CertificateARNSelector, &out.CertificateARNSelector - *out = new(v1.Selector) - (*in).DeepCopyInto(*out) + if in.Certificates != nil { + in, out := &in.Certificates, &out.Certificates + *out = make([]*CustomCertificate, len(*in)) + for i := range *in { + if (*in)[i] != nil { + in, out := &(*in)[i], &(*out)[i] + *out = new(CustomCertificate) + (*in).DeepCopyInto(*out) + } + } } if in.DefaultActions != nil { in, out := &in.DefaultActions, &out.DefaultActions diff --git a/examples/elbv2/listener.yaml b/examples/elbv2/listener.yaml index 1c60bfd0fe..8a0992b783 100644 --- a/examples/elbv2/listener.yaml +++ b/examples/elbv2/listener.yaml @@ -45,8 +45,9 @@ metadata: spec: forProvider: region: us-east-1 - certificateArnRef: - name: dev.crossplane.io + certificates: + - certificateARNRef: + name: dev.crossplane.io defaultActions: - actionType: forward forwardConfig: diff --git a/package/crds/elbv2.aws.crossplane.io_listeners.yaml b/package/crds/elbv2.aws.crossplane.io_listeners.yaml index 47cd1c6604..debb4c870e 100644 --- a/package/crds/elbv2.aws.crossplane.io_listeners.yaml +++ b/package/crds/elbv2.aws.crossplane.io_listeners.yaml @@ -71,33 +71,47 @@ spec: items: type: string type: array - certificateArn: + certificates: description: '[HTTPS and TLS listeners] The default certificate - for the listener.' - type: string - certificateArnRef: - description: Reference to Certificates for Certificate ARN - properties: - name: - description: Name of the referenced object. - type: string - required: - - name - type: object - certificateArnSelector: - description: Selector for references to Certificate for CertificateArn - properties: - matchControllerRef: - description: MatchControllerRef ensures an object with the - same controller reference as the selecting object is selected. - type: boolean - matchLabels: - additionalProperties: + for the listener. You must provide exactly one certificate. + Set CertificateArn to the certificate ARN but do not set IsDefault.' + items: + description: CustomCertificate includes custom fields about + certificates. + properties: + certificateARN: + description: '[HTTPS and TLS listeners] The default certificate + for the listener.' type: string - description: MatchLabels ensures an object with matching labels - is selected. - type: object - type: object + certificateARNRef: + description: Reference to Certificates for Certificate ARN + properties: + name: + description: Name of the referenced object. + type: string + required: + - name + type: object + certificateARNSelector: + description: Selector for references to Certificate for + CertificateArn + properties: + matchControllerRef: + description: MatchControllerRef ensures an object with + the same controller reference as the selecting object + is selected. + type: boolean + matchLabels: + additionalProperties: + type: string + description: MatchLabels ensures an object with matching + labels is selected. + type: object + type: object + isDefault: + type: boolean + type: object + type: array defaultActions: description: The actions for the default rule. items: diff --git a/pkg/controller/elbv2/listener/setup.go b/pkg/controller/elbv2/listener/setup.go index 7048d0006f..b6ecc91a45 100644 --- a/pkg/controller/elbv2/listener/setup.go +++ b/pkg/controller/elbv2/listener/setup.go @@ -220,11 +220,11 @@ func generateDefaultActions(cr *svcapitypes.Listener) []*svcsdk.Action { //nolin func preCreate(_ context.Context, cr *svcapitypes.Listener, obs *svcsdk.CreateListenerInput) error { obs.DefaultActions = generateDefaultActions(cr) obs.LoadBalancerArn = cr.Spec.ForProvider.LoadBalancerARN - if cr.Spec.ForProvider.CertificateARN != nil { - obs.Certificates = []*svcsdk.Certificate{ - { - CertificateArn: cr.Spec.ForProvider.CertificateARN, - }, + for i := range cr.Spec.ForProvider.Certificates { + if cr.Spec.ForProvider.Certificates[i].CertificateARN != nil { + obs.Certificates = append(obs.Certificates, &svcsdk.Certificate{ + CertificateArn: cr.Spec.ForProvider.Certificates[i].CertificateARN, + }) } } return nil