Skip to content

Commit

Permalink
Use new fields and add unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Parraga <sovietaced@gmail.com>
  • Loading branch information
Sovietaced committed Feb 4, 2025
1 parent cf2a7b2 commit 0c44848
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
16 changes: 11 additions & 5 deletions internal/server/submit/conversion/conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func createIngressFromService(
serviceName, namespace, jobId string,
) *armadaevents.KubernetesObject {
rules := make([]networking.IngressRule, 0, len(service.Ports))
tlsHosts := make([]string, 0, len(service.Ports))
tlsHosts := ingressConfig.TlsHosts

// Rest of the hosts are generated off port information
for _, servicePort := range service.Ports {
Expand Down Expand Up @@ -220,17 +220,23 @@ func createIngressFromService(
})
}

ingressSpec := &networking.IngressSpec{
Rules: rules,
TLS: tls,
}

if len(ingressConfig.ClassName) > 0 {
ingressSpec.IngressClassName = &ingressConfig.ClassName
}

return &armadaevents.KubernetesObject{
ObjectMeta: &armadaevents.ObjectMeta{
Name: fmt.Sprintf("%s-ingress-%d", common.PodName(jobId), serviceIdx),
Annotations: util.MergeMaps(map[string]string{}, ingressConfig.Annotations),
Labels: map[string]string{},
},
Object: &armadaevents.KubernetesObject_Ingress{
Ingress: &networking.IngressSpec{
Rules: rules,
TLS: tls,
},
Ingress: ingressSpec,
},
}
}
Expand Down
24 changes: 23 additions & 1 deletion internal/server/submit/conversion/conversions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ func TestCreateIngressFromService(t *testing.T) {
Type: v1.ServiceTypeClusterIP,
}

nginxIngressClassName := "nginx"

defaultIngressRule := networking.IngressRule{
Host: "testContainer-8080-armada-00000000000000000000000001-0.testNamespace.",
IngressRuleValue: networking.IngressRuleValue{
Expand Down Expand Up @@ -261,6 +263,25 @@ func TestCreateIngressFromService(t *testing.T) {
},
},
},
"ingressWithCustomClassName": {
ingressConfig: &api.IngressConfig{
ClassName: nginxIngressClassName,
},
expectedIngress: &armadaevents.KubernetesObject{
ObjectMeta: &armadaevents.ObjectMeta{
Name: "armada-00000000000000000000000001-0-ingress-1",
Annotations: map[string]string{},
Labels: map[string]string{},
},
Object: &armadaevents.KubernetesObject_Ingress{
Ingress: &networking.IngressSpec{
IngressClassName: &nginxIngressClassName,
TLS: []networking.IngressTLS{},
Rules: []networking.IngressRule{defaultIngressRule},
},
},
},
},
"ingressWithDefaultTls": {
ingressConfig: &api.IngressConfig{
TlsEnabled: true,
Expand Down Expand Up @@ -288,6 +309,7 @@ func TestCreateIngressFromService(t *testing.T) {
ingressConfig: &api.IngressConfig{
TlsEnabled: true,
CertName: "testCustomCert",
TlsHosts: []string{"example.com"},
},
expectedIngress: &armadaevents.KubernetesObject{
ObjectMeta: &armadaevents.ObjectMeta{
Expand All @@ -299,7 +321,7 @@ func TestCreateIngressFromService(t *testing.T) {
Ingress: &networking.IngressSpec{
TLS: []networking.IngressTLS{
{
Hosts: []string{"testContainer-8080-armada-00000000000000000000000001-0.testNamespace."},
Hosts: []string{"example.com", "testContainer-8080-armada-00000000000000000000000001-0.testNamespace."},
SecretName: "testCustomCert",
},
},
Expand Down

0 comments on commit 0c44848

Please sign in to comment.