diff --git a/cluster/kube/client_ingress.go b/cluster/kube/client_ingress.go index 69e293bd1..ffe4d0dd8 100644 --- a/cluster/kube/client_ingress.go +++ b/cluster/kube/client_ingress.go @@ -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) @@ -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 } @@ -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, diff --git a/cluster/mocks/client.go b/cluster/mocks/client.go index 8273c2869..3b82bc7a4 100644 --- a/cluster/mocks/client.go +++ b/cluster/mocks/client.go @@ -89,13 +89,13 @@ func (_c *Client_AllHostnames_Call) RunAndReturn(run func(context.Context) ([]v1 return _c } -// ConnectHostnameToDeployment provides a mock function with given fields: ctx, directive +// ConnectHostnameToDeployment provides a mock function with given fields: ctx, directive, tlsEnabled func (_m *Client) ConnectHostnameToDeployment(ctx context.Context, directive v1beta3.ConnectHostnameToDeploymentDirective, tlsEnabled bool) error { - ret := _m.Called(ctx, directive) + ret := _m.Called(ctx, directive, tlsEnabled) var r0 error - if rf, ok := ret.Get(0).(func(context.Context, v1beta3.ConnectHostnameToDeploymentDirective) error); ok { - r0 = rf(ctx, directive) + if rf, ok := ret.Get(0).(func(context.Context, v1beta3.ConnectHostnameToDeploymentDirective, bool) error); ok { + r0 = rf(ctx, directive, tlsEnabled) } else { r0 = ret.Error(0) } @@ -111,13 +111,14 @@ type Client_ConnectHostnameToDeployment_Call struct { // ConnectHostnameToDeployment is a helper method to define mock.On call // - ctx context.Context // - directive v1beta3.ConnectHostnameToDeploymentDirective -func (_e *Client_Expecter) ConnectHostnameToDeployment(ctx interface{}, directive interface{}) *Client_ConnectHostnameToDeployment_Call { - return &Client_ConnectHostnameToDeployment_Call{Call: _e.mock.On("ConnectHostnameToDeployment", ctx, directive)} +// - tlsEnabled bool +func (_e *Client_Expecter) ConnectHostnameToDeployment(ctx interface{}, directive interface{}, tlsEnabled interface{}) *Client_ConnectHostnameToDeployment_Call { + return &Client_ConnectHostnameToDeployment_Call{Call: _e.mock.On("ConnectHostnameToDeployment", ctx, directive, tlsEnabled)} } -func (_c *Client_ConnectHostnameToDeployment_Call) Run(run func(ctx context.Context, directive v1beta3.ConnectHostnameToDeploymentDirective)) *Client_ConnectHostnameToDeployment_Call { +func (_c *Client_ConnectHostnameToDeployment_Call) Run(run func(ctx context.Context, directive v1beta3.ConnectHostnameToDeploymentDirective, tlsEnabled bool)) *Client_ConnectHostnameToDeployment_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(v1beta3.ConnectHostnameToDeploymentDirective)) + run(args[0].(context.Context), args[1].(v1beta3.ConnectHostnameToDeploymentDirective), args[2].(bool)) }) return _c } @@ -127,7 +128,7 @@ func (_c *Client_ConnectHostnameToDeployment_Call) Return(_a0 error) *Client_Con return _c } -func (_c *Client_ConnectHostnameToDeployment_Call) RunAndReturn(run func(context.Context, v1beta3.ConnectHostnameToDeploymentDirective) error) *Client_ConnectHostnameToDeployment_Call { +func (_c *Client_ConnectHostnameToDeployment_Call) RunAndReturn(run func(context.Context, v1beta3.ConnectHostnameToDeploymentDirective, bool) error) *Client_ConnectHostnameToDeployment_Call { _c.Call.Return(run) return _c } diff --git a/operator/hostnameoperator/hostname_operator_test.go b/operator/hostnameoperator/hostname_operator_test.go index 6e857401b..e86047d04 100644 --- a/operator/hostnameoperator/hostname_operator_test.go +++ b/operator/hostnameoperator/hostname_operator_test.go @@ -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) @@ -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) @@ -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)