Skip to content
This repository was archived by the owner on May 24, 2023. It is now read-only.

Commit 7c45d7d

Browse files
committed
Add new CRDs for KIC 1.7
1 parent d47a637 commit 7c45d7d

File tree

12 files changed

+212
-20
lines changed

12 files changed

+212
-20
lines changed

deploy/crds/k8s.nginx.org_nginxingresscontrollers_crd.yaml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@ spec:
5555
controller reporting the status of Ingress resources – only one replica
5656
will report status.
5757
type: boolean
58+
enableTLSPassthrough:
59+
description: Enable TLS Passthrough on port 443. Requires enableCRDs
60+
set to true.
61+
type: boolean
62+
globalConfiguration:
63+
description: The GlobalConfiguration resource for global configuration
64+
of the Ingress Controller. Format is namespace/name. Requires enableCRDs
65+
set to true.
66+
type: string
5867
healthStatus:
5968
description: Adds a new location to the default server. The location
6069
responds with the 200 status code for any request. Useful for external
@@ -123,7 +132,7 @@ spec:
123132
commas. (default “127.0.0.1”)
124133
type: string
125134
enable:
126-
description: Enable the NginxStatus. Default is true.
135+
description: Enable the NginxStatus.
127136
type: boolean
128137
port:
129138
description: Set the port where the NGINX stub_status or the NGINX
@@ -152,7 +161,7 @@ spec:
152161
type: object
153162
replicas:
154163
description: The number of replicas of the Ingress Controller pod. The
155-
default is 1. Only applies if the Kind is set to deployment.
164+
default is 1. Only applies if the type is set to deployment.
156165
format: int32
157166
type: integer
158167
reportIngressStatus:

docs/nginx-ingress-controller.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ spec:
6565
port: 9114
6666
configMapData:
6767
error-log-level: debug
68+
enableTLSPassthrough: true
69+
globalConfiguration: my-nginx-ingress/nginx-configuration
6870
```
6971
7072
| Field | Type | Description | Required |
@@ -88,7 +90,9 @@ spec:
8890
| `wildcardTLS` | `string` | A Secret with a TLS certificate and key for TLS termination of every Ingress host for which TLS termination is enabled but the Secret is not specified. If the argument is not set, for such Ingress hosts NGINX will break any attempt to establish a TLS connection. If the argument is set, but the Ingress controller is not able to fetch the Secret from Kubernetes API, the Ingress Controller will fail to start. Format is `namespace/name`. | No |
8991
| `prometheus` | [prometheus](#nginxingresscontrollerprometheus) | Configures NGINX or NGINX Plus metrics in the Prometheus format. | No |
9092
| `configMapData` | `map[string]string` | Initial values of the Ingress Controller ConfigMap. Check the [ConfigMap docs](https://docs.nginx.com/nginx-ingress-controller/configuration/global-configuration/configmap-resource/) for more information about possible values. | No |
91-
93+
| `globalConfiguration` | `string` | The GlobalConfiguration resource for global configuration of the Ingress Controller. Format is namespace/name. Requires enableCRDs set to true. | No |
94+
| `enableTLSPassthrough` | `boolean` | Enable TLS Passthrough on port 443. Requires enableCRDs set to true. | No |
95+
9296
## NginxIngressController.Image
9397

9498
| Field | Type | Description | Required |

examples/deployment-oss-min/nginx-ingress-controller.yaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ spec:
99
image:
1010
repository: nginx/nginx-ingress
1111
tag: edge
12-
pullPolicy: Always
12+
pullPolicy: IfNotPresent
1313
replicas: 1
1414
serviceType: NodePort
15-
enableCRDs: true
16-
nginxStatus:
17-
enable: true
15+
enableCRDs: true

examples/deployment-plus-min/nginx-ingress-controller.yaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ spec:
99
image:
1010
repository: nginx-plus-ingress
1111
tag: edge
12-
pullPolicy: Always
12+
pullPolicy: IfNotPresent
1313
replicas: 1
1414
serviceType: NodePort
15-
enableCRDs: true
16-
nginxStatus:
17-
enable: true
15+
enableCRDs: true

pkg/apis/k8s/v1alpha1/nginxingresscontroller_types.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@ type NginxIngressControllerSpec struct {
8080
// +kubebuilder:validation:Optional
8181
// +nullable
8282
ConfigMapData map[string]string `json:"configMapData"`
83+
// The GlobalConfiguration resource for global configuration of the Ingress Controller.
84+
// Format is namespace/name.
85+
// Requires enableCRDs set to true.
86+
// +kubebuilder:validation:Optional
87+
GlobalConfiguration string `json:"globalConfiguration"`
88+
// Enable TLS Passthrough on port 443.
89+
// Requires enableCRDs set to true.
90+
// +kubebuilder:validation:Optional
91+
EnableTLSPassthrough bool `json:"enableTLSPassthrough"`
8392
}
8493

8594
// Image defines the Repository, Tag and ImagePullPolicy of the Ingress Controller Image.

pkg/controller/nginxingresscontroller/crds.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,53 @@ func vsrForNginxIngressController() *v1beta1.CustomResourceDefinition {
5454
},
5555
}
5656
}
57+
58+
func gcForNginxIngressController() *v1beta1.CustomResourceDefinition {
59+
return &v1beta1.CustomResourceDefinition{
60+
ObjectMeta: v1.ObjectMeta{
61+
Name: "globalconfigurations.k8s.nginx.org",
62+
},
63+
Spec: v1beta1.CustomResourceDefinitionSpec{
64+
Group: "k8s.nginx.org",
65+
Names: v1beta1.CustomResourceDefinitionNames{
66+
Plural: "globalconfigurations",
67+
Singular: "globalconfiguration",
68+
ShortNames: []string{"gc"},
69+
Kind: "GlobalConfiguration",
70+
},
71+
Scope: "Namespaced",
72+
Versions: []v1beta1.CustomResourceDefinitionVersion{
73+
{
74+
Name: "v1alpha1",
75+
Served: true,
76+
Storage: true,
77+
},
78+
},
79+
},
80+
}
81+
}
82+
83+
func tsForNginxIngressController() *v1beta1.CustomResourceDefinition {
84+
return &v1beta1.CustomResourceDefinition{
85+
ObjectMeta: v1.ObjectMeta{
86+
Name: "transportservers.k8s.nginx.org",
87+
},
88+
Spec: v1beta1.CustomResourceDefinitionSpec{
89+
Group: "k8s.nginx.org",
90+
Names: v1beta1.CustomResourceDefinitionNames{
91+
Plural: "transportservers",
92+
Singular: "transportserver",
93+
ShortNames: []string{"ts"},
94+
Kind: "TransportServer",
95+
},
96+
Scope: "Namespaced",
97+
Versions: []v1beta1.CustomResourceDefinitionVersion{
98+
{
99+
Name: "v1alpha1",
100+
Served: true,
101+
Storage: true,
102+
},
103+
},
104+
},
105+
}
106+
}

pkg/controller/nginxingresscontroller/crds_test.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,63 @@ func TestVsrForNginxIngressController(t *testing.T) {
6767
t.Errorf("vsrForNginxIngressController() returned %+v but expected %+v", result, expected)
6868
}
6969
}
70+
71+
func TestGcForNginxIngressController(t *testing.T) {
72+
expected := &v1beta1.CustomResourceDefinition{
73+
ObjectMeta: v1.ObjectMeta{
74+
Name: "globalconfigurations.k8s.nginx.org",
75+
},
76+
Spec: v1beta1.CustomResourceDefinitionSpec{
77+
Group: "k8s.nginx.org",
78+
Names: v1beta1.CustomResourceDefinitionNames{
79+
Plural: "globalconfigurations",
80+
Singular: "globalconfiguration",
81+
ShortNames: []string{"gc"},
82+
Kind: "GlobalConfiguration",
83+
},
84+
Scope: "Namespaced",
85+
Versions: []v1beta1.CustomResourceDefinitionVersion{
86+
{
87+
Name: "v1alpha1",
88+
Served: true,
89+
Storage: true,
90+
},
91+
},
92+
},
93+
}
94+
95+
result := gcForNginxIngressController()
96+
if !reflect.DeepEqual(result, expected) {
97+
t.Errorf("gcForNginxIngressController() returned %+v but expected %+v", result, expected)
98+
}
99+
}
100+
101+
func TestTsForNginxIngressController(t *testing.T) {
102+
expected := &v1beta1.CustomResourceDefinition{
103+
ObjectMeta: v1.ObjectMeta{
104+
Name: "transportservers.k8s.nginx.org",
105+
},
106+
Spec: v1beta1.CustomResourceDefinitionSpec{
107+
Group: "k8s.nginx.org",
108+
Names: v1beta1.CustomResourceDefinitionNames{
109+
Plural: "transportservers",
110+
Singular: "transportserver",
111+
ShortNames: []string{"ts"},
112+
Kind: "TransportServer",
113+
},
114+
Scope: "Namespaced",
115+
Versions: []v1beta1.CustomResourceDefinitionVersion{
116+
{
117+
Name: "v1alpha1",
118+
Served: true,
119+
Storage: true,
120+
},
121+
},
122+
},
123+
}
124+
125+
result := tsForNginxIngressController()
126+
if !reflect.DeepEqual(result, expected) {
127+
t.Errorf("tsForNginxIngressController() returned %+v but expected %+v", result, expected)
128+
}
129+
}

pkg/controller/nginxingresscontroller/nginxingresscontroller_controller.go

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,24 @@ func createCommonResources(mgr manager.Manager, sccAPIExists bool) error {
5959

6060
err := clientReader.Get(context.TODO(), types.NamespacedName{Name: clusterRoleName, Namespace: v1.NamespaceAll}, cr)
6161

62-
if err != nil && errors.IsNotFound(err) {
63-
reqLogger.Info("no previous ClusterRole found, creating a new one.")
64-
err = clientWriter.Create(context.TODO(), cr)
65-
}
66-
6762
if err != nil {
68-
return fmt.Errorf("error creating ClusterRole: %v", err)
63+
if errors.IsNotFound(err) {
64+
reqLogger.Info("no previous ClusterRole found, creating a new one.")
65+
err = clientWriter.Create(context.TODO(), cr)
66+
if err != nil {
67+
return fmt.Errorf("error creating ClusterRole: %v", err)
68+
}
69+
} else {
70+
return fmt.Errorf("error getting ClusterRole: %v", err)
71+
}
72+
} else {
73+
// For updates in the ClusterRole permissions (eg new CRDs of the Ingress Controller).
74+
reqLogger.Info("previous ClusterRole found, updating.")
75+
cr := clusterRoleForNginxIngressController(clusterRoleName)
76+
err = clientWriter.Update(context.TODO(), cr)
77+
if err != nil {
78+
return fmt.Errorf("error updating ClusterRole: %v", err)
79+
}
6980
}
7081

7182
crb := clusterRoleBindingForNginxIngressController(clusterRoleName)
@@ -91,7 +102,6 @@ func createCommonResources(mgr manager.Manager, sccAPIExists bool) error {
91102
vs := vsForNginxIngressController()
92103

93104
_, err = crdsClient.Create(vs)
94-
// if already exists, pass the error silently
95105
if err != nil && errors.IsAlreadyExists(err) {
96106
reqLogger.Info("VirtualServer CRD already present, skipping creation.")
97107
} else if err != nil {
@@ -106,6 +116,22 @@ func createCommonResources(mgr manager.Manager, sccAPIExists bool) error {
106116
return err
107117
}
108118

119+
gc := gcForNginxIngressController()
120+
_, err = crdsClient.Create(gc)
121+
if err != nil && errors.IsAlreadyExists(err) {
122+
reqLogger.Info("GlobalConfiguration CRD already present, skipping creation.")
123+
} else if err != nil {
124+
return err
125+
}
126+
127+
ts := tsForNginxIngressController()
128+
_, err = crdsClient.Create(ts)
129+
if err != nil && errors.IsAlreadyExists(err) {
130+
reqLogger.Info("TransportServer CRD already present, skipping creation.")
131+
} else if err != nil {
132+
return err
133+
}
134+
109135
if sccAPIExists {
110136
reqLogger.Info("OpenShift detected as platform.")
111137

pkg/controller/nginxingresscontroller/rbac.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func clusterRoleForNginxIngressController(name string) *rbacv1.ClusterRole {
4545
{
4646
Verbs: []string{"get", "list", "watch"},
4747
APIGroups: []string{"k8s.nginx.org"},
48-
Resources: []string{"virtualservers", "virtualserverroutes"},
48+
Resources: []string{"virtualservers", "virtualserverroutes", "globalconfigurations", "transportservers"},
4949
},
5050
}
5151

pkg/controller/nginxingresscontroller/rbac_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func TestClusterRoleForNginxIngressController(t *testing.T) {
5353
{
5454
Verbs: []string{"get", "list", "watch"},
5555
APIGroups: []string{"k8s.nginx.org"},
56-
Resources: []string{"virtualservers", "virtualserverroutes"},
56+
Resources: []string{"virtualservers", "virtualserverroutes", "globalconfigurations", "transportservers"},
5757
},
5858
},
5959
}

pkg/controller/nginxingresscontroller/utils.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package nginxingresscontroller
33
import (
44
"fmt"
55
"reflect"
6+
"strings"
67

78
k8sv1alpha1 "github.com/nginxinc/nginx-ingress-operator/pkg/apis/k8s/v1alpha1"
89
secv1 "github.com/openshift/api/security/v1"
@@ -13,6 +14,8 @@ import (
1314
"sigs.k8s.io/controller-runtime/pkg/client/config"
1415
)
1516

17+
const apiVersionUnsupportedError = "server does not support API version"
18+
1619
// generatePodArgs generate a list of arguments for the Ingress Controller pods based on the CRD.
1720
func generatePodArgs(instance *k8sv1alpha1.NginxIngressController) []string {
1821
var args []string
@@ -98,6 +101,16 @@ func generatePodArgs(instance *k8sv1alpha1.NginxIngressController) []string {
98101
}
99102
}
100103

104+
if instance.Spec.EnableCRDs {
105+
if instance.Spec.EnableTLSPassthrough {
106+
args = append(args, "-enable-tls-passthrough")
107+
}
108+
109+
if instance.Spec.GlobalConfiguration != "" {
110+
args = append(args, fmt.Sprintf("-global-configuration=%v", instance.Spec.GlobalConfiguration))
111+
}
112+
}
113+
101114
return args
102115
}
103116

@@ -143,6 +156,10 @@ func VerifySCCAPIExists() (bool, error) {
143156

144157
err = discovery.ServerSupportsVersion(clientSet, gv)
145158
if err != nil {
159+
// This error means the call could not find SCC in the API, but there was no API error.
160+
if strings.Contains(err.Error(), apiVersionUnsupportedError) {
161+
return false, nil
162+
}
146163
return false, err
147164
}
148165

pkg/controller/nginxingresscontroller/utils_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,25 @@ func TestGeneratePodArgs(t *testing.T) {
120120
fmt.Sprintf("-external-service=%v", name),
121121
},
122122
},
123+
{
124+
instance: &k8sv1alpha1.NginxIngressController{
125+
ObjectMeta: metav1.ObjectMeta{
126+
Name: name,
127+
Namespace: namespace,
128+
},
129+
Spec: k8sv1alpha1.NginxIngressControllerSpec{
130+
EnableCRDs: true,
131+
EnableTLSPassthrough: true,
132+
GlobalConfiguration: "my-nginx-ingress/globalconfiguration",
133+
},
134+
},
135+
expected: []string{
136+
"-nginx-configmaps=my-nginx-ingress/my-nginx-ingress",
137+
"-default-server-tls-secret=my-nginx-ingress/my-nginx-ingress",
138+
"-enable-tls-passthrough",
139+
"-global-configuration=my-nginx-ingress/globalconfiguration",
140+
},
141+
},
123142
{
124143
instance: &k8sv1alpha1.NginxIngressController{
125144
ObjectMeta: metav1.ObjectMeta{
@@ -154,6 +173,8 @@ func TestGeneratePodArgs(t *testing.T) {
154173
Enable: true,
155174
Port: 9114,
156175
},
176+
GlobalConfiguration: "my-nginx-ingress/globalconfiguration",
177+
EnableTLSPassthrough: true,
157178
},
158179
},
159180
expected: []string{

0 commit comments

Comments
 (0)