Skip to content

Commit 9baf863

Browse files
committed
Checks for annotation for objects in-cluster
1 parent 1d1fd97 commit 9baf863

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

pkg/patterns/declarative/reconciler.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import (
2020
"context"
2121
"errors"
2222
"fmt"
23+
"k8s.io/apimachinery/pkg/api/meta"
24+
"k8s.io/client-go/dynamic"
2325
"path/filepath"
2426
"strings"
2527

@@ -184,6 +186,40 @@ func (r *Reconciler) reconcileExists(ctx context.Context, name types.NamespacedN
184186
if err != nil {
185187
return reconcile.Result{}, err
186188
}
189+
190+
// dynamic config
191+
dynamicClientset, err := dynamic.NewForConfig(r.config)
192+
if err != nil {
193+
log.Error(err,"Unable to create dynamic client")
194+
return reconcile.Result{}, err
195+
}
196+
197+
newItems := []*manifest.Object{}
198+
for _, obj := range objects.Items {
199+
200+
// Uses unsafe method?? Is it safe?
201+
getOptions := metav1.GetOptions{}
202+
gvk, _ := meta.UnsafeGuessKindToResource(obj.GroupVersionKind())
203+
ns := obj.UnstructuredObject().GetNamespace()
204+
unstruct, err := dynamicClientset.Resource(gvk).Namespace(ns).Get(context.Background(),
205+
obj.Name, getOptions)
206+
if err != nil{
207+
log.WithValues("name", obj.Name).Error(err, "Unable to get resource")
208+
}
209+
if unstruct != nil {
210+
annotations := unstruct.GetAnnotations()
211+
if ignoreAnnotation, ok := annotations["addons.operators.ignore"]; ok {
212+
if ignoreAnnotation == "true" {
213+
log.WithValues("kind", obj.Kind).WithValues("name", obj.Name).Info("Found ignore annotation on object, " +
214+
"skipping object")
215+
continue
216+
}
217+
}
218+
}
219+
newItems = append(newItems, obj)
220+
}
221+
objects.Items = newItems
222+
187223
var manifestStr string
188224

189225
m, err := objects.JSONManifest()

0 commit comments

Comments
 (0)