Skip to content

Commit

Permalink
Allow control of managed-by label through use of environment variable
Browse files Browse the repository at this point in the history
Related: #1357

This allows the label to be controlled in a simple way for now

```
▶ PULUMI_KUBERNETES_MANAGED_BY_LABEL=mycompany pulumi up
Previewing update (dev)
     Type                             Name                      Plan
 +   pulumi:pulumi:Stack              testing-new-workflow-dev  create
 +   └─ kubernetes:core/v1:Namespace  nginx                     create
Resources:
    + 2 to create
Do you want to perform this update? details
+ pulumi:pulumi:Stack: (create)
    [urn=urn:pulumi:dev::testing-new-workflow::pulumi:pulumi:Stack::testing-new-workflow-dev]
    + kubernetes:core/v1:Namespace: (create)
        [urn=urn:pulumi:dev::testing-new-workflow::kubernetes:core/v1:Namespace::nginx]
        [provider=urn:pulumi:dev::testing-new-workflow::pulumi:providers:kubernetes::default_2_8_0::04da6b54-80e4-46f7-96ec-b56ff0331ba9]
        apiVersion: "v1"
        kind      : "Namespace"
        metadata  : {
            labels: {
                app.kubernetes.io/managed-by: "mycompany"
            }
            name  : "testing"
        }
```
  • Loading branch information
stack72 committed Feb 12, 2021
1 parent 3f93ad6 commit b379b7b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- Skip Helm test hook resources by default (https://github.com/pulumi/pulumi-kubernetes/pull/1467)
- Ensure no panic when a kubernetes provider is used with an incompatible resource type (https://github.com/pulumi/pulumi-kubernetes/pull/1469)
- Allow users to set `PULUMI_KUBERNETES_MANAGED_BY_LABEL` environment variable to control `app.kubernetes.io/managed-by` label (https://github.com/pulumi/pulumi-kubernetes/pull/1471)

## 2.8.0 (February 3, 2021)

Expand Down
8 changes: 7 additions & 1 deletion provider/pkg/metadata/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package metadata

import (
"fmt"
"os"
"reflect"

"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
Expand Down Expand Up @@ -90,7 +91,12 @@ func GetLabel(obj *unstructured.Unstructured, key string) interface{} {
// (e.g.) the underlying object is mistyped. In particular, TrySetLabel will fail if the underlying
// object has a Pulumi computed value.
func TrySetManagedByLabel(obj *unstructured.Unstructured) (bool, error) {
return TrySetLabel(obj, managedByLabel, "pulumi")
managedBy := "pulumi"
labelVal, exists := os.LookupEnv("PULUMI_KUBERNETES_MANAGED_BY_LABEL")
if exists {
managedBy = labelVal
}
return TrySetLabel(obj, managedByLabel, managedBy)
}

// HasManagedByLabel returns true if the object has the `app.kubernetes.io/managed-by` label set to `pulumi`,
Expand Down

0 comments on commit b379b7b

Please sign in to comment.