-
Notifications
You must be signed in to change notification settings - Fork 90
/
registry.go
33 lines (27 loc) · 1.05 KB
/
registry.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
30
31
32
33
package resources
import (
"context"
"github.com/pkg/errors"
kotsadmobjects "github.com/replicatedhq/kots/pkg/kotsadm/objects"
"github.com/replicatedhq/kots/pkg/kotsadm/types"
kuberneteserrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
)
func EnsurePrivateKotsadmRegistrySecret(namespace string, registryConfig types.RegistryConfig, clientset kubernetes.Interface) error {
_, err := clientset.CoreV1().Secrets(namespace).Get(context.TODO(), types.PrivateKotsadmRegistrySecret, metav1.GetOptions{})
if err != nil {
if !kuberneteserrors.IsNotFound(err) {
return errors.Wrap(err, "failed to get existing private kotsadm registry secret")
}
secret := kotsadmobjects.PrivateKotsadmRegistrySecret(namespace, registryConfig)
if secret == nil {
return nil
}
_, err := clientset.CoreV1().Secrets(namespace).Create(context.TODO(), secret, metav1.CreateOptions{})
if err != nil {
return errors.Wrap(err, "failed to create private kotsadm registry secret")
}
}
return nil
}