Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Clowder to reconcile on changes to non-app secrets/configmaps #1122

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ func (r *ClowdEnvironmentReconciler) Reconcile(ctx context.Context, req ctrl.Req
env: &env,
log: &log,
oldStatus: env.Status.DeepCopy(),
hashCache: r.HashCache,
}

result, resErr := reconciliation.Reconcile()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

crd "github.com/RedHatInsights/clowder/apis/cloud.redhat.com/v1alpha1"
"github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/clowderconfig"
"github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/hashcache"
"github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/providers"
rc "github.com/RedHatInsights/rhc-osdk-utils/resourceCache"
"github.com/go-logr/logr"
Expand Down Expand Up @@ -57,6 +58,7 @@ type ClowdEnvironmentReconciliation struct {
env *crd.ClowdEnvironment
log *logr.Logger
oldStatus *crd.ClowdEnvironmentStatus
hashCache *hashcache.HashCache
}

// Returns a list of step methods that should be run during reconciliation
Expand Down Expand Up @@ -285,6 +287,9 @@ func (r *ClowdEnvironmentReconciliation) isTargetNamespaceMarkedForDeletion() (c
}

func (r *ClowdEnvironmentReconciliation) runProviders() (ctrl.Result, error) {

r.hashCache.RemoveClowdObjectFromObjects(r.env)

provider := providers.Provider{
Ctx: r.ctx,
Client: r.client,
Expand Down
10 changes: 9 additions & 1 deletion controllers/cloud.redhat.com/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,15 @@ func (e *enqueueRequestForObjectCustom) updateHashCacheForConfigMapAndSecret(obj
switch obj.(type) {
case *core.ConfigMap, *core.Secret:
if obj.GetAnnotations()[clowderconfig.LoadedConfig.Settings.RestarterAnnotationName] == "true" {
return e.hashCache.CreateOrUpdateObject(obj)
return e.hashCache.CreateOrUpdateObject(obj, false)
} else {
hcOjb, err := e.hashCache.Read(obj)
if err != nil {
return false, err
}
if hcOjb.Always {
return e.hashCache.CreateOrUpdateObject(obj, false)
}
}
}
return false, nil
Expand Down
17 changes: 10 additions & 7 deletions controllers/cloud.redhat.com/hashcache/hashcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type HashObject struct {
Hash string
ClowdApps map[types.NamespacedName]bool
ClowdEnvs map[types.NamespacedName]bool
Always bool
}

type HashCache struct {
Expand All @@ -46,11 +47,12 @@ func NewHashCache() HashCache {
}
}

func NewHashObject(hash string) HashObject {
func NewHashObject(hash string, always bool) HashObject {
return HashObject{
Hash: hash,
ClowdApps: map[types.NamespacedName]bool{},
ClowdEnvs: map[types.NamespacedName]bool{},
Always: always,
}
}

Expand Down Expand Up @@ -101,7 +103,7 @@ func (hc *HashCache) RemoveClowdObjectFromObjects(obj client.Object) {
}
}

func (hc *HashCache) CreateOrUpdateObject(obj client.Object) (bool, error) {
func (hc *HashCache) CreateOrUpdateObject(obj client.Object, always bool) (bool, error) {
hc.lock.Lock()
defer hc.lock.Unlock()

Expand Down Expand Up @@ -129,7 +131,7 @@ func (hc *HashCache) CreateOrUpdateObject(obj client.Object) (bool, error) {
hashObject, ok := hc.data[id]

if !ok {
hashObj := NewHashObject(hash)
hashObj := NewHashObject(hash, always)
hc.data[id] = &hashObj
return true, nil
}
Expand Down Expand Up @@ -178,10 +180,6 @@ func (hc *HashCache) GetSuperHashForClowdObject(clowdObj object.ClowdObject) str

func (hc *HashCache) AddClowdObjectToObject(clowdObj object.ClowdObject, obj client.Object) error {

if obj.GetAnnotations()[clowderconfig.LoadedConfig.Settings.RestarterAnnotationName] != "true" {
return nil
}

var oType string

switch obj.(type) {
Expand All @@ -198,6 +196,11 @@ func (hc *HashCache) AddClowdObjectToObject(clowdObj object.ClowdObject, obj cli
if !ok {
return ItemNotFoundError{item: fmt.Sprintf("%s/%s", id.NN.Name, id.NN.Namespace)}
}

if obj.GetAnnotations()[clowderconfig.LoadedConfig.Settings.RestarterAnnotationName] != "true" && !hc.data[id].Always {
return nil
}

hc.lock.Lock()
defer hc.lock.Unlock()

Expand Down
16 changes: 8 additions & 8 deletions controllers/cloud.redhat.com/hashcache/hashcache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestHashCacheAddItemAndRetrieve(t *testing.T) {
}

hc := NewHashCache()
update, err := hc.CreateOrUpdateObject(sec)
update, err := hc.CreateOrUpdateObject(sec, false)
assert.NoError(t, err)
assert.True(t, update)
obj, err := hc.Read(sec)
Expand All @@ -39,7 +39,7 @@ func TestHashCacheDeleteItem(t *testing.T) {
}

hc := NewHashCache()
shouldUpdate, err := hc.CreateOrUpdateObject(sec)
shouldUpdate, err := hc.CreateOrUpdateObject(sec, false)
assert.True(t, shouldUpdate)
assert.NoError(t, err)
obj, err := hc.Read(sec)
Expand All @@ -63,7 +63,7 @@ func TestHashCacheUpdateItem(t *testing.T) {
}

hc := NewHashCache()
_, err := hc.CreateOrUpdateObject(sec)
_, err := hc.CreateOrUpdateObject(sec, false)
assert.NoError(t, err)

obj, err := hc.Read(sec)
Expand All @@ -75,7 +75,7 @@ func TestHashCacheUpdateItem(t *testing.T) {
"test2": []byte("test2"),
}

update, err := hc.CreateOrUpdateObject(sec)
update, err := hc.CreateOrUpdateObject(sec, false)
assert.NoError(t, err)
assert.True(t, update)
obj, err = hc.Read(sec)
Expand Down Expand Up @@ -120,7 +120,7 @@ func TestHashCacheAddClowdObj(t *testing.T) {
}

hc := NewHashCache()
_, err := hc.CreateOrUpdateObject(sec)
_, err := hc.CreateOrUpdateObject(sec, false)
assert.NoError(t, err)

err = hc.AddClowdObjectToObject(capp, sec)
Expand Down Expand Up @@ -152,7 +152,7 @@ func TestHashCacheDeleteClowdObj(t *testing.T) {
}

hc := NewHashCache()
_, err := hc.CreateOrUpdateObject(sec)
_, err := hc.CreateOrUpdateObject(sec, false)
assert.NoError(t, err)

err = hc.AddClowdObjectToObject(capp, sec)
Expand Down Expand Up @@ -196,15 +196,15 @@ func TestHashCacheSuperCache(t *testing.T) {
}

hc := NewHashCache()
_, err := hc.CreateOrUpdateObject(sec)
_, err := hc.CreateOrUpdateObject(sec, false)
assert.NoError(t, err)
err = hc.AddClowdObjectToObject(capp, sec)
assert.NoError(t, err)
obj, err := hc.Read(sec)
assert.NoError(t, err)
assert.Contains(t, obj.ClowdApps, clowdObjNamespaceName)

_, err = hc.CreateOrUpdateObject(sec2)
_, err = hc.CreateOrUpdateObject(sec2, false)
assert.NoError(t, err)
err = hc.AddClowdObjectToObject(capp, sec2)
assert.NoError(t, err)
Expand Down
10 changes: 10 additions & 0 deletions controllers/cloud.redhat.com/providers/kafka/appinterface.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ func (a *appInterface) setKafkaCA(broker *config.BrokerConfig) error {
return err
}

_, err := a.HashCache.CreateOrUpdateObject(&kafkaCASecret, true)
if err != nil {
return err
}

err = a.HashCache.AddClowdObjectToObject(a.Env, &kafkaCASecret)
if err != nil {
return err
}

broker.Cacert = utils.StringPtr(string(kafkaCASecret.Data["ca.crt"]))
broker.Port = utils.IntPtr(9093)
broker.SecurityProtocol = utils.StringPtr("SSL")
Expand Down
Loading