Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Certificate refs for https listeners #1211

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
24 changes: 24 additions & 0 deletions apis/elbv2/v1alpha1/custom_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -91,6 +109,12 @@ type CustomAction struct {

// CustomListenerParameters includes the custom fields of Listener.
type CustomListenerParameters struct {
// [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
Certificates []*CustomCertificate `json:"certificates,omitempty"`

// The actions for the default rule.
// +kubebuilder:validation:Required
DefaultActions []*CustomAction `json:"defaultActions"`
Expand Down
17 changes: 17 additions & 0 deletions apis/elbv2/v1alpha1/referencers.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +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 certificate ARN reference
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
}

// resolve loadbalancer ARN reference
rsp, err := r.Resolve(ctx, reference.ResolutionRequest{
CurrentValue: reference.FromPtrValue(mg.Spec.ForProvider.LoadBalancerARN),
Expand Down
52 changes: 41 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.

23 changes: 23 additions & 0 deletions examples/elbv2/listener.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,26 @@ 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
certificates:
- 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
29 changes: 29 additions & 0 deletions package/crds/elbv2.aws.crossplane.io_listeners.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,38 @@ spec:
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
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
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
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
}

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.