Skip to content

Commit

Permalink
Add Certificate refs for https listeners
Browse files Browse the repository at this point in the history
Signed-off-by: EdgeJ <[email protected]>
  • Loading branch information
EdgeJ committed Mar 15, 2022
1 parent f9a5b77 commit b2e2e03
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 79 deletions.
1 change: 1 addition & 0 deletions apis/elbv2/generator-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ ignore:
field_paths:
- CreateListenerInput.LoadBalancerArn
- CreateListenerInput.DefaultActions
- CreateListenerInput.Certificates
# Type has a json key of type_, so it's reimplemented with loadBalancerType
- CreateLoadBalancerInput.Type
resource_names:
Expand Down
10 changes: 10 additions & 0 deletions apis/elbv2/v1alpha1/custom_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ type CustomAction struct {

// CustomListenerParameters includes the custom fields of Listener.
type CustomListenerParameters struct {
// [HTTPS and TLS listeners] The default certificate for the listener.
// +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"`

// The actions for the default rule.
// +kubebuilder:validation:Required
DefaultActions []*CustomAction `json:"defaultActions"`
Expand Down
17 changes: 16 additions & 1 deletion apis/elbv2/v1alpha1/referencers.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,30 @@ import (
"github.com/pkg/errors"
"sigs.k8s.io/controller-runtime/pkg/client"

acm "github.com/crossplane/provider-aws/apis/acm/v1beta1"
ec2 "github.com/crossplane/provider-aws/apis/ec2/v1beta1"
)

// ResolveReferences resolves references for Listeners
func (mg *Listener) ResolveReferences(ctx context.Context, c client.Reader) error {
r := reference.NewAPIResolver(c, mg)

// resolve loadbalancer ARN reference
// 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")
}
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{
CurrentValue: reference.FromPtrValue(mg.Spec.ForProvider.LoadBalancerARN),
Reference: mg.Spec.ForProvider.LoadBalancerARNRef,
Selector: mg.Spec.ForProvider.LoadBalancerARNSelector,
Expand Down
26 changes: 15 additions & 11 deletions apis/elbv2/v1alpha1/zz_generated.deepcopy.go

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

4 changes: 0 additions & 4 deletions apis/elbv2/v1alpha1/zz_listener.go

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

22 changes: 22 additions & 0 deletions examples/elbv2/listener.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,25 @@ spec:
protocol: HTTP
providerConfigRef:
name: example
---
apiVersion: elbv2.aws.crossplane.io/v1alpha1
kind: Listener
metadata:
name: test-listener-https
spec:
forProvider:
region: us-east-1
certificateArnRef:
name: dev.crossplane.io
defaultActions:
- actionType: forward
forwardConfig:
targetGroups:
- targetGroupArnRef:
name: test-targetgroup
loadBalancerArnRef:
name: test-loadbalancer
port: 443
protocol: HTTPS
providerConfigRef:
name: example
35 changes: 25 additions & 10 deletions package/crds/elbv2.aws.crossplane.io_listeners.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,33 @@ spec:
items:
type: string
type: array
certificates:
certificateArn:
description: '[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.'
items:
properties:
certificateARN:
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:
type: string
isDefault:
type: boolean
type: object
type: array
description: MatchLabels ensures an object with matching labels
is selected.
type: object
type: object
defaultActions:
description: The actions for the default rule.
items:
Expand Down
7 changes: 7 additions & 0 deletions pkg/controller/elbv2/listener/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,13 @@ 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,
},
}
}
return nil
}

Expand Down
62 changes: 9 additions & 53 deletions pkg/controller/elbv2/listener/zz_conversions.go

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

0 comments on commit b2e2e03

Please sign in to comment.