Skip to content

Commit

Permalink
Set managed-by: pulumi label on all created resources (#418)
Browse files Browse the repository at this point in the history
  • Loading branch information
lblackstone committed Feb 12, 2019
1 parent 37e50ae commit f23736e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/await/await.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/golang/glog"
"github.com/pulumi/pulumi-kubernetes/pkg/clients"
"github.com/pulumi/pulumi-kubernetes/pkg/metadata"
"github.com/pulumi/pulumi-kubernetes/pkg/openapi"
"github.com/pulumi/pulumi-kubernetes/pkg/retry"
"github.com/pulumi/pulumi/pkg/diag"
Expand Down Expand Up @@ -108,6 +109,9 @@ func Creation(c CreateConfig) (*unstructured.Unstructured, error) {
}
}

// Set a "managed-by: pulumi" label on all created k8s resources.
metadata.SetManagedByLabel(c.Inputs)

outputs, err = client.Create(c.Inputs, metav1.CreateOptions{})
if err != nil {
_ = c.Host.LogStatus(c.Context, diag.Info, c.URN, fmt.Sprintf(
Expand Down
32 changes: 32 additions & 0 deletions pkg/metadata/labels.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2016-2019, Pulumi Corporation.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package metadata

import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
)

func SetLabel(obj *unstructured.Unstructured, key, value string) {
labels := obj.GetLabels()
if labels == nil {
labels = map[string]string{}
}
labels[key] = value
obj.SetLabels(labels)
}

func SetManagedByLabel(obj *unstructured.Unstructured) {
SetLabel(obj, "app.kubernetes.io/managed-by", "pulumi")
}

0 comments on commit f23736e

Please sign in to comment.