Skip to content

Commit dee8036

Browse files
committed
Add explanations to certs and move a struct
1 parent 3f0d910 commit dee8036

File tree

2 files changed

+69
-47
lines changed

2 files changed

+69
-47
lines changed

hack/tls-cert-gen/certs.go

Lines changed: 69 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
package main
22

3+
// yamlSecret encapsulates all the data that we need to create the tls secrets
4+
// that kubernetes needs as tls files.
5+
//
6+
// secretName - this is what virtualservers and other objects reference
7+
// fileName - every secret needs to have an actual file on the disk. This is going to be the name of the file that's placed in the ./common-secrets directory
8+
// symlinks - a slice of paths that will symlink to the actual file. These paths are relative to the project root. For example: []string{"examples/custom-resources/oidc/tls-secret.yaml"}
9+
// valid - whether the generated kubernetes secret file should be valid. An invalid secret will not have the data["tls.key"] property set in the yaml file.
10+
// templateData - has information about issuer, subject, common name (main domain), and dnsNames (subject alternate names).
11+
// secretType - if left empty, it will be the default v1.SecretTypeTLS value. The type is "k8s.io/api/core/v1".SecretType, which is an alias for strings.
12+
// usedIn - not used in the generation, it's only so we can keep track on which py tests used the specific certs
13+
type yamlSecret struct {
14+
secretName string
15+
fileName string
16+
symlinks []string
17+
valid bool
18+
templateData templateData
19+
secretType string
20+
usedIn []string
21+
}
22+
323
var yamlSecrets = []yamlSecret{
424
{
525
secretName: "tls-secret",
@@ -70,47 +90,54 @@ var yamlSecrets = []yamlSecret{
7090
},
7191
},
7292

93+
// ==== the below ones are needed for specific pytests ===
7394
{
74-
secretName: "default-server-secret",
75-
fileName: "tls-secret-default.yaml",
95+
secretName: "tls-secret",
96+
fileName: "tls-secret-gb.yaml",
7697
templateData: templateData{
77-
country: []string{"IE"},
78-
organization: []string{"F5 NGINX"},
79-
organizationalUnit: []string{"NGINX Ingress Controller"},
80-
locality: []string{"Cork"},
81-
province: []string{"Cork"},
82-
commonName: "NGINXIngressController",
83-
dnsNames: []string{"*.example.com"},
98+
country: []string{"GB"},
99+
organization: []string{"nginx"},
100+
locality: []string{"Cork"},
101+
province: []string{"Cambridgeshire"},
102+
commonName: "cafe.example.com",
103+
dnsNames: []string{"example.com", "*.example.com"},
84104
},
85105
valid: secretShouldHaveValidTLSCrt,
86106
symlinks: []string{
87-
"/examples/shared-examples/default-server-secret/default-server-secret.yaml",
88-
"/tests/data/common/default-server-secret.yaml",
107+
"/tests/data/tls/new-tls-secret.yaml",
108+
"/tests/data/virtual-server-tls/new-tls-secret.yaml",
109+
},
110+
usedIn: []string{
111+
"tests/suite/test_tls.py - needed for subject info and common name",
112+
"tests/suite/test_virtual_server_tls.py - needed for subject info and common name",
89113
},
90114
},
91115

92116
{
93117
secretName: "default-server-secret",
94-
fileName: "tls-secret-invalid.yaml",
118+
fileName: "tls-secret-default.yaml",
95119
templateData: templateData{
96120
country: []string{"IE"},
97121
organization: []string{"F5 NGINX"},
98122
organizationalUnit: []string{"NGINX Ingress Controller"},
99123
locality: []string{"Cork"},
100124
province: []string{"Cork"},
101-
commonName: "example.com",
125+
commonName: "NGINXIngressController",
102126
dnsNames: []string{"*.example.com"},
103127
},
104-
valid: secretShouldHaveInvalidTLSCrt,
128+
valid: secretShouldHaveValidTLSCrt,
105129
symlinks: []string{
106-
"/tests/data/default-server/invalid-tls-secret.yaml",
130+
"/examples/shared-examples/default-server-secret/default-server-secret.yaml",
131+
"/tests/data/common/default-server-secret.yaml",
132+
},
133+
usedIn: []string{
134+
"tests/suite/test_default_server.py - needed for secret name and common name",
107135
},
108136
},
109137

110-
// ==== the below ones are needed for specific pytests ===
111138
{
112-
secretName: "tls-secret",
113-
fileName: "tls-secret-gb.yaml",
139+
secretName: "default-server-secret",
140+
fileName: "tls-secret-default-gb.yaml",
114141
templateData: templateData{
115142
country: []string{"GB"},
116143
organization: []string{"nginx"},
@@ -121,25 +148,31 @@ var yamlSecrets = []yamlSecret{
121148
},
122149
valid: secretShouldHaveValidTLSCrt,
123150
symlinks: []string{
124-
"/tests/data/tls/new-tls-secret.yaml",
125-
"/tests/data/virtual-server-tls/new-tls-secret.yaml",
151+
"/tests/data/default-server/new-tls-secret.yaml",
152+
},
153+
usedIn: []string{
154+
"tests/suite/test_default_server.py - needed for secret name and common name",
126155
},
127156
},
128157

129158
{
130159
secretName: "default-server-secret",
131-
fileName: "tls-secret-default-gb.yaml",
160+
fileName: "tls-secret-invalid.yaml",
132161
templateData: templateData{
133-
country: []string{"GB"},
134-
organization: []string{"nginx"},
135-
locality: []string{"Cork"},
136-
province: []string{"Cambridgeshire"},
137-
commonName: "cafe.example.com",
138-
dnsNames: []string{"example.com", "*.example.com"},
162+
country: []string{"IE"},
163+
organization: []string{"F5 NGINX"},
164+
organizationalUnit: []string{"NGINX Ingress Controller"},
165+
locality: []string{"Cork"},
166+
province: []string{"Cork"},
167+
commonName: "example.com",
168+
dnsNames: []string{"*.example.com"},
139169
},
140-
valid: secretShouldHaveValidTLSCrt,
170+
valid: secretShouldHaveInvalidTLSCrt,
141171
symlinks: []string{
142-
"/tests/data/default-server/new-tls-secret.yaml",
172+
"/tests/data/default-server/invalid-tls-secret.yaml",
173+
},
174+
usedIn: []string{
175+
"tests/suite/test_default_server.py - needed for the secret name",
143176
},
144177
},
145178

@@ -159,6 +192,10 @@ var yamlSecrets = []yamlSecret{
159192
"/tests/data/tls/tls-secret.yaml",
160193
"/tests/data/virtual-server-tls/tls-secret.yaml",
161194
},
195+
usedIn: []string{
196+
"tests/suite/test_tls.py - needed for subject info and common name",
197+
"tests/suite/test_virtual_server_tls.py - needed for subject info and common name",
198+
},
162199
},
163200
{
164201
secretName: "tls-secret",
@@ -177,5 +214,8 @@ var yamlSecrets = []yamlSecret{
177214
"/tests/data/tls/invalid-tls-secret.yaml",
178215
},
179216
secretType: "some type",
217+
usedIn: []string{
218+
"tests/suite/test_tls.py - needed for the secretType",
219+
},
180220
},
181221
}

hack/tls-cert-gen/tls-cert-gen.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -60,24 +60,6 @@ type templateData struct {
6060
dnsNames []string
6161
}
6262

63-
// yamlSecret encapsulates all the data that we need to create the tls secrets
64-
// that kubernetes needs as tls files.
65-
//
66-
// secretName - this is what virtualservers and other objects reference
67-
// fileName - every secret needs to have an actual file on the disk. This is going to be the name of the file that's placed in the ./common-secrets directory
68-
// symlinks - a slice of paths that will symlink to the actual file. These paths are relative to the project root. For example: []string{"examples/custom-resources/oidc/tls-secret.yaml"}
69-
// valid - whether the generated kubernetes secret file should be valid. An invalid secret will not have the data["tls.key"] property set in the yaml file.
70-
// templateData - has information about issuer, subject, common name (main domain), and dnsNames (subject alternate names).
71-
// secretType - if left empty, it will be the default v1.SecretTypeTLS value. The type is "k8s.io/api/core/v1".SecretType, which is an alias for strings.
72-
type yamlSecret struct {
73-
secretName string
74-
fileName string
75-
symlinks []string
76-
valid bool
77-
templateData templateData
78-
secretType string
79-
}
80-
8163
func main() {
8264
logger := slog.New(slog.NewTextHandler(os.Stdout, nil))
8365
var err error

0 commit comments

Comments
 (0)