Skip to content

Commit 7d15bd2

Browse files
authored
Merge pull request #120 from SomtochiAma/aggregate-status-ns
Aggregate status looks in the correct namespace
2 parents 5adb43c + e778f94 commit 7d15bd2

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

pkg/patterns/addon/pkg/status/aggregate.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,20 @@ func (a *aggregator) Reconciled(ctx context.Context, src declarative.Declarative
5454
for _, o := range objs.Items {
5555
gk := o.Group + "/" + o.Kind
5656
healthy := true
57+
objKey := client.ObjectKey{
58+
Name: o.Name,
59+
Namespace: o.Namespace,
60+
}
61+
// If the namespace isn't set on the object, we would want to use the namespace of src
62+
if objKey.Namespace == "" {
63+
objKey.Namespace = src.GetNamespace()
64+
}
5765
var err error
5866
switch gk {
5967
case "/Service":
60-
healthy, err = a.service(ctx, src, o.Name)
68+
healthy, err = a.service(ctx, objKey)
6169
case "extensions/Deployment", "apps/Deployment":
62-
healthy, err = a.deployment(ctx, src, o.Name)
70+
healthy, err = a.deployment(ctx, objKey)
6371
default:
6472
log.WithValues("type", gk).V(2).Info("type not implemented for status aggregation, skipping")
6573
}
@@ -129,8 +137,7 @@ func (a *aggregator) Reconciled(ctx context.Context, src declarative.Declarative
129137
return nil
130138
}
131139

132-
func (a *aggregator) deployment(ctx context.Context, src declarative.DeclarativeObject, name string) (bool, error) {
133-
key := client.ObjectKey{Name: name}
140+
func (a *aggregator) deployment(ctx context.Context, key client.ObjectKey) (bool, error) {
134141
dep := &appsv1.Deployment{}
135142

136143
if err := a.client.Get(ctx, key, dep); err != nil {
@@ -146,8 +153,7 @@ func (a *aggregator) deployment(ctx context.Context, src declarative.Declarative
146153
return false, fmt.Errorf("deployment (%s) does not meet condition: %s", key, successfulDeployment)
147154
}
148155

149-
func (a *aggregator) service(ctx context.Context, src declarative.DeclarativeObject, name string) (bool, error) {
150-
key := client.ObjectKey{Namespace: src.GetNamespace(), Name: name}
156+
func (a *aggregator) service(ctx context.Context, key client.ObjectKey) (bool, error) {
151157
svc := &corev1.Service{}
152158
err := a.client.Get(ctx, key, svc)
153159
if err != nil {

pkg/patterns/declarative/pkg/manifest/objects.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ type Objects struct {
3939
type Object struct {
4040
object *unstructured.Unstructured
4141

42-
Group string
43-
Kind string
44-
Name string
42+
Group string
43+
Kind string
44+
Name string
45+
Namespace string
4546

4647
json []byte
4748
}
@@ -58,11 +59,12 @@ func ParseJSONToObject(json []byte) (*Object, error) {
5859
}
5960

6061
return &Object{
61-
object: u,
62-
Group: gvk.Group,
63-
Kind: gvk.Kind,
64-
Name: u.GetName(),
65-
json: json,
62+
object: u,
63+
Group: gvk.Group,
64+
Kind: gvk.Kind,
65+
Name: u.GetName(),
66+
Namespace: u.GetNamespace(),
67+
json: json,
6668
}, nil
6769
}
6870

@@ -360,6 +362,7 @@ func newObject(u *unstructured.Unstructured, json []byte) (*Object, error) {
360362
o.Group = gvk.Group
361363
o.Kind = gvk.Kind
362364
o.Name = u.GetName()
365+
o.Namespace = u.GetNamespace()
363366

364367
return o, nil
365368
}

0 commit comments

Comments
 (0)