Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkowl committed Aug 5, 2024
1 parent 939f5af commit 5aefdaf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
10 changes: 6 additions & 4 deletions pkg/cluster/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"

"github.com/Azure/ARO-RP/pkg/env"
"github.com/Azure/ARO-RP/pkg/util/clienthelper"
"github.com/Azure/ARO-RP/pkg/util/keyvault"
utilpem "github.com/Azure/ARO-RP/pkg/util/pem"
)

func EnsureTLSSecretFromKeyvault(ctx context.Context, env env.Interface, ch clienthelper.Interface, target types.NamespacedName, certificateName string) error {
bundle, err := env.ClusterKeyvault().GetSecret(ctx, certificateName)
func EnsureTLSSecretFromKeyvault(ctx context.Context, kv keyvault.Manager, ch clienthelper.Writer, target types.NamespacedName, certificateName string) error {
bundle, err := kv.GetSecret(ctx, certificateName)
if err != nil {
return err
}
Expand All @@ -38,14 +38,16 @@ func EnsureTLSSecretFromKeyvault(ctx context.Context, env env.Interface, ch clie
cb = append(cb, pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: cert.Raw})...)
}

privateKey := pem.EncodeToMemory(&pem.Block{Type: "PRIVATE KEY", Bytes: b})

secret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: target.Name,
Namespace: target.Namespace,
},
Data: map[string][]byte{
corev1.TLSCertKey: cb,
corev1.TLSPrivateKeyKey: pem.EncodeToMemory(&pem.Block{Type: "PRIVATE KEY", Bytes: b}),
corev1.TLSPrivateKeyKey: privateKey,
},
Type: corev1.SecretTypeTLS,
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cluster/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (m *manager) configureAPIServerCertificate(ctx context.Context) error {
}

for _, namespace := range []string{"openshift-config", "openshift-azure-operator"} {
err = EnsureTLSSecretFromKeyvault(ctx, m.env, m.ch, types.NamespacedName{Name: m.doc.ID + "-apiserver", Namespace: namespace}, m.doc.ID+"-apiserver")
err = EnsureTLSSecretFromKeyvault(ctx, m.env.ClusterKeyvault(), m.ch, types.NamespacedName{Name: m.doc.ID + "-apiserver", Namespace: namespace}, m.doc.ID+"-apiserver")
if err != nil {
return err
}
Expand Down Expand Up @@ -123,7 +123,7 @@ func (m *manager) configureIngressCertificate(ctx context.Context) error {
}

for _, namespace := range []string{"openshift-ingress", "openshift-azure-operator"} {
err = EnsureTLSSecretFromKeyvault(ctx, m.env, m.ch, types.NamespacedName{Namespace: namespace, Name: m.doc.ID + "-ingress"}, m.doc.ID+"-ingress")
err = EnsureTLSSecretFromKeyvault(ctx, m.env.ClusterKeyvault(), m.ch, types.NamespacedName{Namespace: namespace, Name: m.doc.ID + "-ingress"}, m.doc.ID+"-ingress")
if err != nil {
return err
}
Expand Down
16 changes: 13 additions & 3 deletions pkg/util/clienthelper/clienthelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,24 @@ import (
_ "github.com/Azure/ARO-RP/pkg/util/scheme"
)

type Interface interface {
client.Reader
type Writer interface {
client.Writer
EnsureDeleted(ctx context.Context, gvk schema.GroupVersionKind, key types.NamespacedName) error
// Ensure applies self-contained objects to a Kubernetes API, merging
// client-side if required.
Ensure(ctx context.Context, objs ...kruntime.Object) error
EnsureDeleted(ctx context.Context, gvk schema.GroupVersionKind, key types.NamespacedName) error
}

type Reader interface {
client.Reader
GetOne(ctx context.Context, key types.NamespacedName, obj kruntime.Object) error
}

type Interface interface {
Reader
Writer
}

type clientHelper struct {
client.Client

Expand Down

0 comments on commit 5aefdaf

Please sign in to comment.