8000 Support non-vs created Challenge Ingress (#3463) · nginx/kubernetes-ingress@1cbe236 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1cbe236

Browse files
ciarams87lucacome
authored andcommitted
Support non-vs created Challenge Ingress (#3463)
(cherry picked from commit 241e7a3)
1 parent c5cfbc6 commit 1cbe236

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

internal/k8s/configuration.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,11 +1299,11 @@ func (c *Configuration) buildHostsAndResources() (newHosts map[string]Resource,
12991299
var resource *IngressConfiguration
13001300

13011301
if val := c.isChallengeIngress(ing); val {
1302-
// if using cert-manager with Ingress, the challenge Ingress must be Minion
1303-
// and this code won't be reached. With VS, the challenge Ingress must not be Minion.
13041302
vsr := c.convertIngressToVSR(ing)
1305-
challengesVSR = append(challengesVSR, vsr)
1306-
continue
1303+
if vsr != nil {
1304+
challengesVSR = append(challengesVSR, vsr)
1305+
continue
1306+
}
13071307
}
13081308

13091309
if isMaster(ing) {
@@ -1407,6 +1407,10 @@ func (c *Configuration) isChallengeIngress(ing *networking.Ingress) bool {
14071407
func (c *Configuration) convertIngressToVSR(ing *networking.Ingress) *conf_v1.VirtualServerRoute {
14081408
rule := ing.Spec.Rules[0]
14091409

1410+
if !c.isChallengeIngressOwnerVs(rule.Host) {
1411+
return nil
1412+
}
1413+
14101414
vs := &conf_v1.VirtualServerRoute{
14111415
ObjectMeta: metav1.ObjectMeta{
14121416
Namespace: ing.Namespace,
@@ -1435,6 +1439,16 @@ func (c *Configuration) convertIngressToVSR(ing *networking.Ingress) *conf_v1.Vi
14351439
return vs
14361440
}
14371441

1442+
func (c *Configuration) isChallengeIngressOwnerVs(host string) bool {
1443+
for _, key := range getSortedVirtualServerKeys(c.virtualServers) {
1444+
vs := c.virtualServers[key]
1445+
if host == vs.Spec.Host {
1446+
return true
1447+
}
1448+
}
1449+
return false
1450+
}
1451+
14381452
func (c *Configuration) buildMinionConfigs(masterHost string) ([]*MinionConfiguration, map[string][]string) {
14391453
var minionConfigs []*MinionConfiguration
14401454
childWarnings := make(map[string][]string)

internal/k8s/configuration_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2761,6 +2761,36 @@ func TestChallengeIngressToVSR(t *testing.T) {
27612761
}
27622762
}
27632763

2764+
func TestChallengeIngressNoVSR(t *testing.T) {
2765+
configuration := createTestConfiguration()
2766+
2767+
var expectedProblems []ConfigurationProblem
2768+
2769+
vs := createTestVirtualServer("virtualserver", "bar.example.com")
2770+
ing := createTestChallengeIngress("challenge", "foo.example.com", "/.well-known/acme-challenge/test", "cm-acme-http-solver-test")
2771+
configuration.AddOrUpdateVirtualServer(vs)
2772+
expectedChanges := []ResourceChange{
2773+
{
2774+
Op: AddOrUpdate,
2775+
Resource: &IngressConfiguration{
2776+
Ingress: ing,
2777+
ValidHosts: map[string]bool{
2778+
"foo.example.com": true,
2779+
},
2780+
ChildWarnings: map[string][]string{},
2781+
},
2782+
},
2783+
}
2784+
2785+
changes, problems := configuration.AddOrUpdateIngress(ing)
2786+
if diff := cmp.Diff(expectedChanges, changes); diff != "" {
2787+
t.Errorf("AddOrUpdateIngress() returned unexpected result (-want +got):\n%s", diff)
2788+
}
2789+
if diff := cmp.Diff(expectedProblems, problems); diff != "" {
2790+
t.Errorf("AddOrUpdateIngress() returned unexpected result (-want +got):\n%s", diff)
2791+
}
2792+
}
2793+
27642794
func mustInitGlobalConfiguration(c *Configuration, gc *conf_v1alpha1.GlobalConfiguration) {
27652795
changes, problems, err := c.AddOrUpdateGlobalConfiguration(gc)
27662796

0 commit comments

Comments
 (0)
0