Skip to content

Commit

Permalink
cmd/manager: deprecate subobject deletion flag, add event and log not…
Browse files Browse the repository at this point in the history
…ifications
  • Loading branch information
s-urbaniak committed Feb 13, 2024
1 parent cedd141 commit 349b2ff
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
46 changes: 39 additions & 7 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package main

import (
"context"
"errors"
"flag"
"fmt"
Expand All @@ -25,6 +26,8 @@ import (
"strings"
"time"

"sigs.k8s.io/controller-runtime/pkg/manager"

"go.uber.org/zap/zapcore"
ctrzap "sigs.k8s.io/controller-runtime/pkg/log/zap"

Expand Down Expand Up @@ -64,7 +67,11 @@ const (
objectDeletionProtectionEnvVar = "OBJECT_DELETION_PROTECTION"
subobjectDeletionProtectionEnvVar = "SUBOBJECT_DELETION_PROTECTION"
objectDeletionProtectionDefault = true
subobjectDeletionProtectionDefault = true
subobjectDeletionProtectionDefault = false

podNamespace = "POD_NAMESPACE"
podName = "POD_NAME"
subobjectDeletionProtectionMessage = "Note: sub-object deletion protection is IGNORED because it does not work deterministically."
)

var (
Expand Down Expand Up @@ -147,7 +154,7 @@ func main() {
EventRecorder: mgr.GetEventRecorderFor("AtlasDeployment"),
AtlasProvider: atlasProvider,
ObjectDeletionProtection: config.ObjectDeletionProtection,
SubObjectDeletionProtection: config.SubObjectDeletionProtection,
SubObjectDeletionProtection: false,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "AtlasDeployment")
os.Exit(1)
Expand All @@ -162,7 +169,7 @@ func main() {
EventRecorder: mgr.GetEventRecorderFor("AtlasProject"),
AtlasProvider: atlasProvider,
ObjectDeletionProtection: config.ObjectDeletionProtection,
SubObjectDeletionProtection: config.SubObjectDeletionProtection,
SubObjectDeletionProtection: false,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "AtlasProject")
os.Exit(1)
Expand All @@ -177,7 +184,7 @@ func main() {
AtlasProvider: atlasProvider,
GlobalPredicates: globalPredicates,
ObjectDeletionProtection: config.ObjectDeletionProtection,
SubObjectDeletionProtection: config.SubObjectDeletionProtection,
SubObjectDeletionProtection: false,
FeaturePreviewOIDCAuthEnabled: config.FeatureFlags.IsFeaturePresent(featureflags.FeatureOIDC),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "AtlasDatabaseUser")
Expand All @@ -193,7 +200,7 @@ func main() {
EventRecorder: mgr.GetEventRecorderFor("AtlasDataFederation"),
AtlasProvider: atlasProvider,
ObjectDeletionProtection: config.ObjectDeletionProtection,
SubObjectDeletionProtection: config.SubObjectDeletionProtection,
SubObjectDeletionProtection: false,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "AtlasDataFederation")
os.Exit(1)
Expand All @@ -208,7 +215,7 @@ func main() {
EventRecorder: mgr.GetEventRecorderFor("AtlasFederatedAuth"),
AtlasProvider: atlasProvider,
ObjectDeletionProtection: config.ObjectDeletionProtection,
SubObjectDeletionProtection: config.SubObjectDeletionProtection,
SubObjectDeletionProtection: false,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "AtlasFederatedAuth")
os.Exit(1)
Expand All @@ -225,6 +232,31 @@ func main() {
os.Exit(1)
}

err = mgr.Add(manager.RunnableFunc(func(ctx context.Context) error {
setupLog.Info(subobjectDeletionProtectionMessage)

akoPod := &corev1.Pod{}
err = mgr.GetClient().Get(ctx, client.ObjectKey{
Namespace: os.Getenv(podNamespace),
Name: os.Getenv(podName),
}, akoPod)

if err == nil {
mgr.GetEventRecorderFor("AtlasKubernetesOperator").Event(
akoPod,
corev1.EventTypeNormal,
"AKOSubObjectDeletionProtection",
subobjectDeletionProtectionMessage,
)
}

return nil
}))
if err != nil {
setupLog.Error(err, "unable to set up runnable")
os.Exit(1)
}

setupLog.Info("starting manager")
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
setupLog.Error(err, "problem running manager")
Expand Down Expand Up @@ -264,7 +296,7 @@ func parseConfiguration() Config {
flag.BoolVar(&config.ObjectDeletionProtection, objectDeletionProtectionFlag, objectDeletionProtectionDefault, "Defines if the operator deletes Atlas resource "+
"when a Custom Resource is deleted")
flag.BoolVar(&config.SubObjectDeletionProtection, subobjectDeletionProtectionFlag, subobjectDeletionProtectionDefault, "Defines if the operator overwrites "+
"(and consequently delete) subresources that were not previously created by the operator")
"(and consequently delete) subresources that were not previously created by the operator. "+subobjectDeletionProtectionMessage)
appVersion := flag.Bool("v", false, "prints application version")
flag.Parse()

Expand Down
2 changes: 1 addition & 1 deletion cmd/manager/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func Test_configureDeletionProtection(t *testing.T) {
t,
Config{
ObjectDeletionProtection: true,
SubObjectDeletionProtection: true,
SubObjectDeletionProtection: false,
},
config,
)
Expand Down

0 comments on commit 349b2ff

Please sign in to comment.