-
Notifications
You must be signed in to change notification settings - Fork 90
/
ingress.go
29 lines (25 loc) · 1.08 KB
/
ingress.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package kotsadm
import (
"context"
"github.com/pkg/errors"
kotsv1beta1 "github.com/replicatedhq/kots/kotskinds/apis/kots/v1beta1"
"github.com/replicatedhq/kots/pkg/ingress"
kotsadmobjects "github.com/replicatedhq/kots/pkg/kotsadm/objects"
kuberneteserrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
)
func EnsureIngress(ctx context.Context, namespace string, clientset *kubernetes.Clientset, ingressSpec kotsv1beta1.IngressConfigSpec) error {
if !ingressSpec.Enabled || ingressSpec.Ingress == nil {
return DeleteIngress(ctx, namespace, clientset)
}
kotsadmIngress := kotsadmobjects.KotsadmIngress(namespace, *ingressSpec.Ingress)
return ingress.EnsureIngress(ctx, clientset, namespace, kotsadmIngress)
}
func DeleteIngress(ctx context.Context, namespace string, clientset *kubernetes.Clientset) error {
err := clientset.ExtensionsV1beta1().Ingresses(namespace).Delete(ctx, "kotsadm", metav1.DeleteOptions{})
if kuberneteserrors.IsNotFound(err) {
err = nil
}
return errors.Wrap(err, "failed to delete ingress")
}