Skip to content

Commit

Permalink
refactor: Apply suggestions on #86
Browse files Browse the repository at this point in the history
  • Loading branch information
cloud-j-luna committed Apr 14, 2023
1 parent 60c4599 commit faabd57
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
14 changes: 7 additions & 7 deletions cluster/kube/client_ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ import (

const (
akashIngressClassName = "akash-ingress-class"
root = "nginx.ingress.kubernetes.io"
certManager = "cert-manager.io"
)

func kubeNginxIngressAnnotations(directive ctypes.ConnectHostnameToDeploymentDirective, env map[string]string) map[string]string {
func (c *client) kubeNginxIngressAnnotations(directive ctypes.ConnectHostnameToDeploymentDirective) map[string]string {
// For kubernetes/ingress-nginx
// https://github.com/kubernetes/ingress-nginx
const root = "nginx.ingress.kubernetes.io"
const certManager = "cert-manager.io"

readTimeout := math.Ceil(float64(directive.ReadTimeout) / 1000.0)
sendTimeout := math.Ceil(float64(directive.SendTimeout) / 1000.0)
Expand Down Expand Up @@ -67,12 +67,12 @@ func kubeNginxIngressAnnotations(directive ctypes.ConnectHostnameToDeploymentDir
}
}

switch env["AKASH_PROVIDER_ISSUER_TYPE"] {
switch c.env["AKASH_PROVIDER_ISSUER_TYPE"] {
case "cluster-issuer":
result[fmt.Sprintf("%s/cluster-issuer", certManager)] = env["AKASH_PROVIDER_ISSUER_NAME"]
result[fmt.Sprintf("%s/cluster-issuer", certManager)] = c.env["AKASH_PROVIDER_ISSUER_NAME"]
break
case "issuer":
result[fmt.Sprintf("%s/issuer", certManager)] = env["AKASH_PROVIDER_ISSUER_NAME"]
result[fmt.Sprintf("%s/issuer", certManager)] = c.env["AKASH_PROVIDER_ISSUER_NAME"]
break
}

Expand Down Expand Up @@ -107,7 +107,7 @@ func (c *client) ConnectHostnameToDeployment(ctx context.Context, directive ctyp
ObjectMeta: metav1.ObjectMeta{
Name: ingressName,
Labels: labels,
Annotations: kubeNginxIngressAnnotations(directive, c.env),
Annotations: c.kubeNginxIngressAnnotations(directive),
},
Spec: netv1.IngressSpec{
IngressClassName: &ingressClassName,
Expand Down
19 changes: 10 additions & 9 deletions cluster/mocks/client.go

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

8 changes: 4 additions & 4 deletions operator/hostnameoperator/hostname_operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ func TestHostnameOperatorApplyAdd(t *testing.T) {
}
s.client.On("GetManifestGroup", mock.Anything, leaseID).Return(true, mg, nil)
directive := buildDirective(ev, serviceExpose) // result tested in other unit tests
s.client.On("ConnectHostnameToDeployment", mock.Anything, directive).Return(nil)
s.client.On("ConnectHostnameToDeployment", mock.Anything, directive, mock.Anything).Return(nil)

managed := grabManagedHostnames(t, s.op.server.GetRouter().ServeHTTP)
require.Empty(t, managed)
Expand Down Expand Up @@ -511,7 +511,7 @@ func TestHostnameOperatorApplyAddMultipleServices(t *testing.T) {
}
s.client.On("GetManifestGroup", mock.Anything, leaseID).Return(true, mg, nil)
directive := buildDirective(ev, serviceExpose) // result tested in other unit tests
s.client.On("ConnectHostnameToDeployment", mock.Anything, directive).Return(nil)
s.client.On("ConnectHostnameToDeployment", mock.Anything, directive, mock.Anything).Return(nil)

err := s.op.applyEvent(s.ctx, ev)
require.NoError(t, err)
Expand Down Expand Up @@ -596,9 +596,9 @@ func TestHostnameOperatorApplyUpdate(t *testing.T) {
s.client.On("GetManifestGroup", mock.Anything, secondLeaseID).Return(true, mg2, nil)

directive := buildDirective(ev, serviceExpose) // result tested in other unit tests
s.client.On("ConnectHostnameToDeployment", mock.Anything, directive).Return(nil)
s.client.On("ConnectHostnameToDeployment", mock.Anything, directive, mock.Anything).Return(nil)
secondDirective := buildDirective(secondEv, secondServiceExpose) // result tested in other unit tests
s.client.On("ConnectHostnameToDeployment", mock.Anything, secondDirective).Return(nil)
s.client.On("ConnectHostnameToDeployment", mock.Anything, secondDirective, mock.Anything).Return(nil)

s.client.On("RemoveHostnameFromDeployment", mock.Anything, hostname, leaseID, false).Return(nil)

Expand Down

0 comments on commit faabd57

Please sign in to comment.