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

--default-ssl-certificate flag for via CRD #160

Merged
merged 24 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e6e947d
Squashed Changes for DefaultSSLCertificate
aamgayle Jan 29, 2024
1e5b5e1
small refactor and ingress controller test
aamgayle Jan 29, 2024
1907fc1
nginx test with ssl cert
aamgayle Jan 29, 2024
1be3cbe
CRD update and small refactor
aamgayle Jan 29, 2024
cb5af4c
tests (unit/e2e) and CRD update
aamgayle Jan 29, 2024
1196135
inherit immutable fields in placeholder pod reconciler (#153)
OliverMKing Jan 23, 2024
b88e386
add 0.2.1 to changelog (#154)
OliverMKing Jan 23, 2024
5e20b87
Bump golang.org/x/crypto from 0.12.0 to 0.17.0 (#146)
dependabot[bot] Jan 29, 2024
96dcb7c
updates to CRD and tests
aamgayle Jan 29, 2024
cfd147d
Merge branch 'main' into aamgayle/defaultsslcertargcopy
aamgayle Jan 30, 2024
f0a2b60
small refactor
aamgayle Jan 30, 2024
08979eb
Added field name for Secret
aamgayle Jan 30, 2024
bb2ca17
Addressing comments
aamgayle Jan 30, 2024
0298201
removed invalid defaultsslcert message from reconciler
aamgayle Jan 30, 2024
96aff17
Fixed nginx ingress controller test
aamgayle Jan 30, 2024
79db9cd
fixed nginx_test
aamgayle Jan 30, 2024
2b98ddc
added nil check for DefaultSSLCertificate
aamgayle Jan 30, 2024
c3c2790
Updated comments and added CEL validation for Secret
aamgayle Jan 31, 2024
c5ba151
More cases for unit testing and returning e2e tests
aamgayle Jan 31, 2024
9c797bc
More cases for unit testing and returning e2e tests
aamgayle Jan 31, 2024
9374b59
Removed redundant CEL validation for secret fields
aamgayle Feb 1, 2024
7614337
Merge branch 'main' into aamgayle/defaultsslcertargcopy
aamgayle Feb 1, 2024
a3b7596
Merge branch 'main' into aamgayle/defaultsslcertargcopy
aamgayle Feb 1, 2024
7eff4ed
Fixed e2e test
aamgayle Feb 2, 2024
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
22 changes: 22 additions & 0 deletions api/v1alpha1/nginxingresscontroller_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,28 @@ type NginxIngressControllerSpec struct {
// will be from the Azure LoadBalancer annotations here https://cloud-provider-azure.sigs.k8s.io/topics/loadbalancer/#loadbalancer-annotations
// +optional
LoadBalancerAnnotations map[string]string `json:"loadBalancerAnnotations,omitempty"`

// DefaultSSLCertificate is a struct with a secret with the fields namespace and name which is used to create the ssl certificate used by the default HTTPS server
aamgayle marked this conversation as resolved.
Show resolved Hide resolved
// +optional
DefaultSSLCertificate DefaultSSLCertificate `json:"defaultSSLCertificate,omitempty"`
aamgayle marked this conversation as resolved.
Show resolved Hide resolved
}

type DefaultSSLCertificate struct {
// Secret is a struct that holds the name and namespace fields used for the default ssl secret
// +optional
Secret Secret `json:"secret"`
aamgayle marked this conversation as resolved.
Show resolved Hide resolved
}

type Secret struct {
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=253
// +kubebuilder:validation:Pattern=`^[a-z0-9][-a-z0-9\.]*[a-z0-9]$`
Name string `json:"secretName"`
aamgayle marked this conversation as resolved.
Show resolved Hide resolved

// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=253
// +kubebuilder:validation:Pattern=`^[a-z0-9][-a-z0-9\.]*[a-z0-9]$`
Namespace string `json:"secretNamespace"`
aamgayle marked this conversation as resolved.
Show resolved Hide resolved
}

// NginxIngressControllerStatus defines the observed state of NginxIngressController
Expand Down
32 changes: 32 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,30 @@ spec:
x-kubernetes-validations:
- message: Value is immutable
rule: self == oldSelf
defaultSSLCertificate:
description: DefaultSSLCertificate is a struct with a secret with
the fields namespace and name which is used to create the ssl certificate
used by the default HTTPS server
properties:
secret:
description: Secret is a struct that holds the name and namespace
fields used for the default ssl secret
properties:
secretName:
maxLength: 253
minLength: 1
pattern: ^[a-z0-9][-a-z0-9\.]*[a-z0-9]$
type: string
secretNamespace:
maxLength: 253
minLength: 1
pattern: ^[a-z0-9][-a-z0-9\.]*[a-z0-9]$
type: string
required:
- secretName
- secretNamespace
type: object
type: object
ingressClassName:
default: nginx.approuting.kubernetes.azure.com
description: IngressClassName is the name of the IngressClass that
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ require (
github.com/prometheus/common v0.44.0
github.com/stretchr/testify v1.8.4
go.uber.org/zap v1.25.0
gomodules.xyz/jsonpatch/v2 v2.4.0
k8s.io/api v0.28.1
k8s.io/apiextensions-apiserver v0.28.1
k8s.io/apimachinery v0.28.1
Expand Down Expand Up @@ -73,6 +72,7 @@ require (
golang.org/x/term v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.3.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
Expand Down
17 changes: 16 additions & 1 deletion pkg/controller/nginxingress/nginx_ingress_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,13 @@ func (n *nginxIngressControllerReconciler) Reconcile(ctx context.Context, req ct
controllerDeployment = resources.Deployment
ingressClass = resources.IngressClass

if &nginxIngressController.Spec.DefaultSSLCertificate != nil {
aamgayle marked this conversation as resolved.
Show resolved Hide resolved
lgr.Info("validating default ssl certificate secret")
if !manifests.IsValidDefaultSSLCertSecret(&nginxIngressController.Spec.DefaultSSLCertificate) {
lgr.Info("Field in DefaultSSLCert secret is invalid or empty: default ssl cert will not be set")
}
}

lgr.Info("reconciling managed resources")
managedRes, err = n.ReconcileResource(ctx, &nginxIngressController, resources)
if err != nil {
Expand Down Expand Up @@ -518,12 +525,20 @@ func ToNginxIngressConfig(nic *approutingv1alpha1.NginxIngressController, defaul
resourceName = DefaultNicResourceName
}

return &manifests.NginxIngressConfig{
nginxIng := &manifests.NginxIngressConfig{
ControllerClass: cc,
ResourceName: resourceName,
IcName: nic.Spec.IngressClassName,
ServiceConfig: &manifests.ServiceConfig{
Annotations: nic.Spec.LoadBalancerAnnotations,
},
}

if manifests.IsValidDefaultSSLCertSecret(&nic.Spec.DefaultSSLCertificate) {
nginxIng.DefaultSSLCertificate = &approutingv1alpha1.DefaultSSLCertificate{
Secret: nic.Spec.DefaultSSLCertificate.Secret,
}
}

return nginxIng
}
30 changes: 30 additions & 0 deletions pkg/controller/nginxingress/nginx_ingress_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,12 @@ func TestIsUnreconcilableError(t *testing.T) {

func TestToNginxIngressConfig(t *testing.T) {
defaultCc := "defaultControllerClass"
FakeDefaultSSLCert := approutingv1alpha1.DefaultSSLCertificate{
Secret: approutingv1alpha1.Secret{
Name: "fakename",
Namespace: "fakenamespace",
},
}
cases := []struct {
name string
nic *approutingv1alpha1.NginxIngressController
Expand Down Expand Up @@ -883,6 +889,30 @@ func TestToNginxIngressConfig(t *testing.T) {
IcName: "ingressClassName",
},
},
{
name: "default controller class with DefaultSSLCertificate",
nic: &approutingv1alpha1.NginxIngressController{
TypeMeta: metav1.TypeMeta{
APIVersion: approutingv1alpha1.GroupVersion.String(),
Kind: "NginxIngressController",
},
ObjectMeta: metav1.ObjectMeta{
Name: DefaultNicName,
},
Spec: approutingv1alpha1.NginxIngressControllerSpec{
ControllerNamePrefix: DefaultNicResourceName,
IngressClassName: DefaultIcName,
DefaultSSLCertificate: FakeDefaultSSLCert,
},
},
want: manifests.NginxIngressConfig{
ControllerClass: defaultCc,
ResourceName: DefaultNicResourceName,
IcName: DefaultIcName,
ServiceConfig: &manifests.ServiceConfig{},
DefaultSSLCertificate: &FakeDefaultSSLCert,
},
},
}

for _, c := range cases {
Expand Down
Loading
Loading