Skip to content

Commit

Permalink
Emit warning event when internal docker registry is configured
Browse files Browse the repository at this point in the history
  • Loading branch information
kwiatekus committed Apr 29, 2024
1 parent f16934e commit 5738c4d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions components/operator/internal/state/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ const (
extRegSecDiffThanSpecFormat = "actual registry configuration comes from %s/%s and it is different from spec.dockerRegistry.secretName. Reflect the %s secret in the secretName field or delete it"
extRegSecNotInSpecFormat = "actual registry configuration comes from %s/%s and it is different from spec.dockerRegistry.secretName. Reflect %s secret in the secretName field"
internalEnabledAndSecretNameUsedMessage = "spec.dockerRegistry.enableInternal is true and spec.dockerRegistry.secretName is used. Delete the secretName field or set the enableInternal value to false"
internalRegistryEventType = "Warning"
internalRegistryEventReason = "Internal Docker Registry option configured"
internalRegistryEventMessage = "Be advised: Internal Docker Registry is not Highly Available registry and should be used for development purpose only"
)

func sFnRegistryConfiguration(ctx context.Context, r *reconciler, s *systemState) (stateFn, *ctrl.Result, error) {
Expand Down Expand Up @@ -67,6 +70,7 @@ func addRegistryConfigurationWarnings(s *systemState) {
}

func setInternalRegistryConfig(ctx context.Context, r *reconciler, s *systemState) error {
r.Event(&s.instance, internalRegistryEventType, internalRegistryEventReason, internalRegistryEventMessage)
s.instance.Status.DockerRegistry = "internal"
s.flagsBuilder.WithRegistryEnableInternal(
*s.instance.Spec.DockerRegistry.EnableInternal,
Expand Down
9 changes: 8 additions & 1 deletion components/operator/internal/state/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ import (
"go.uber.org/zap"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/tools/record"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
)

func Test_sFnRegistryConfiguration(t *testing.T) {
t.Run("internal registry and update", func(t *testing.T) {
eventRecorder := record.NewFakeRecorder(5)
s := &systemState{
instance: v1alpha1.Serverless{
Spec: v1alpha1.ServerlessSpec{
Expand All @@ -32,7 +34,10 @@ func Test_sFnRegistryConfiguration(t *testing.T) {
flagsBuilder: chart.NewFlagsBuilder(),
}
r := &reconciler{
k8s: k8s{client: fake.NewClientBuilder().Build()},
k8s: k8s{
client: fake.NewClientBuilder().Build(),
EventRecorder: eventRecorder,
},
log: zap.NewNop().Sugar(),
}
expectedFlags := map[string]interface{}{
Expand All @@ -52,6 +57,8 @@ func Test_sFnRegistryConfiguration(t *testing.T) {
require.EqualValues(t, expectedFlags, s.flagsBuilder.Build())
require.Equal(t, "internal", s.instance.Status.DockerRegistry)
require.Equal(t, v1alpha1.StateProcessing, s.instance.Status.State)

require.Len(t, eventRecorder.Events, 1)
})

t.Run("external registry and go to next state", func(t *testing.T) {
Expand Down

0 comments on commit 5738c4d

Please sign in to comment.