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

Aggregate status looks in the correct namespace #120

Merged
merged 2 commits into from
Sep 22, 2020
Merged
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
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