Skip to content

Commit

Permalink
Merge pull request #120 from SomtochiAma/aggregate-status-ns
Browse files Browse the repository at this point in the history
Aggregate status looks in the correct namespace
  • Loading branch information
k8s-ci-robot committed Sep 22, 2020
2 parents 5adb43c + e778f94 commit 7d15bd2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
18 changes: 12 additions & 6 deletions pkg/patterns/addon/pkg/status/aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,20 @@ func (a *aggregator) Reconciled(ctx context.Context, src declarative.Declarative
for _, o := range objs.Items {
gk := o.Group + "/" + o.Kind
healthy := true
objKey := client.ObjectKey{
Name: o.Name,
Namespace: o.Namespace,
}
// If the namespace isn't set on the object, we would want to use the namespace of src
if objKey.Namespace == "" {
objKey.Namespace = src.GetNamespace()
}
var err error
switch gk {
case "/Service":
healthy, err = a.service(ctx, src, o.Name)
healthy, err = a.service(ctx, objKey)
case "extensions/Deployment", "apps/Deployment":
healthy, err = a.deployment(ctx, src, o.Name)
healthy, err = a.deployment(ctx, objKey)
default:
log.WithValues("type", gk).V(2).Info("type not implemented for status aggregation, skipping")
}
Expand Down Expand Up @@ -129,8 +137,7 @@ func (a *aggregator) Reconciled(ctx context.Context, src declarative.Declarative
return nil
}

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

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

func (a *aggregator) service(ctx context.Context, src declarative.DeclarativeObject, name string) (bool, error) {
key := client.ObjectKey{Namespace: src.GetNamespace(), Name: name}
func (a *aggregator) service(ctx context.Context, key client.ObjectKey) (bool, error) {
svc := &corev1.Service{}
err := a.client.Get(ctx, key, svc)
if err != nil {
Expand Down
19 changes: 11 additions & 8 deletions pkg/patterns/declarative/pkg/manifest/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ type Objects struct {
type Object struct {
object *unstructured.Unstructured

Group string
Kind string
Name string
Group string
Kind string
Name string
Namespace string

json []byte
}
Expand All @@ -58,11 +59,12 @@ func ParseJSONToObject(json []byte) (*Object, error) {
}

return &Object{
object: u,
Group: gvk.Group,
Kind: gvk.Kind,
Name: u.GetName(),
json: json,
object: u,
Group: gvk.Group,
Kind: gvk.Kind,
Name: u.GetName(),
Namespace: u.GetNamespace(),
json: json,
}, nil
}

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

return o, nil
}
Expand Down

0 comments on commit 7d15bd2

Please sign in to comment.