Skip to content

Commit

Permalink
Revert "Make configmaps mutable unless marked explicitly"
Browse files Browse the repository at this point in the history
This reverts commit 8f1fba6.
  • Loading branch information
viveklak committed Mar 10, 2022
1 parent 8f1fba6 commit a9083f2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 27 deletions.
20 changes: 1 addition & 19 deletions provider/pkg/clients/clients.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016-2022, Pulumi Corporation.
// 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.
Expand All @@ -20,8 +20,6 @@ import (
"io"
"strings"

"github.com/pulumi/pulumi-kubernetes/provider/v3/pkg/openapi"

"github.com/pulumi/pulumi-kubernetes/provider/v3/pkg/kinds"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -245,19 +243,3 @@ func IsCRD(obj *unstructured.Unstructured) bool {
return obj.GetKind() == string(kinds.CustomResourceDefinition) &&
strings.HasPrefix(obj.GetAPIVersion(), "apiextensions.k8s.io/")
}

// IsImmutableConfigMap returns true if the resource is a configmap marked as immutable.
func IsImmutableConfigMap(obj *unstructured.Unstructured) bool {
gvk := obj.GroupVersionKind()
if (gvk.Group == corev1.GroupName || gvk.Group == "core") && gvk.Kind == string(kinds.ConfigMap) {
immutable, ok := openapi.Pluck(obj.Object, "immutable")
if ok {
immutableBool, ok := immutable.(bool)
if ok {
return false
}
return immutableBool
}
}
return false
}
9 changes: 3 additions & 6 deletions provider/pkg/provider/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,15 @@
package provider

import (
"github.com/pulumi/pulumi-kubernetes/provider/v3/pkg/clients"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
)

func forceNewProperties(obj *unstructured.Unstructured) []string {
gvk := obj.GroupVersionKind()
func forceNewProperties(gvk schema.GroupVersionKind) []string {
props := metadataForceNewProperties(".metadata")
if group, groupExists := forceNew[gvk.Group]; groupExists {
if version, versionExists := group[gvk.Version]; versionExists {
if kindFields, kindExists := version[gvk.Kind]; kindExists {
props = append(props, kindFields...)
} else if clients.IsImmutableConfigMap(obj) {
props = append(props, properties{".binaryData", ".data"}...)
}
}
}
Expand Down Expand Up @@ -81,6 +77,7 @@ var forceNew = _groups{

var core = _versions{
"v1": _kinds{
"ConfigMap": properties{".binaryData", ".data"},
"PersistentVolume": append(
properties{
".spec.awsElasticBlockStore",
Expand Down
4 changes: 2 additions & 2 deletions provider/pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1521,7 +1521,7 @@ func (k *kubeProvider) Diff(ctx context.Context, req *pulumirpc.DiffRequest) (*p
changes = append(changes, k)
}

forceNewFields := forceNewProperties(oldInputs)
forceNewFields := forceNewProperties(gvk)
if detailedDiff, err = convertPatchToDiff(patchObj, patchBase, newInputs.Object, oldInputs.Object, forceNewFields...); err != nil {
return nil, pkgerrors.Wrapf(
err, "Failed to check for changes in resource %s/%s because of an error "+
Expand Down Expand Up @@ -1559,7 +1559,7 @@ func (k *kubeProvider) Diff(ctx context.Context, req *pulumirpc.DiffRequest) (*p
// Delete before replacement if we are forced to replace the old object, and the new version of
// that object MUST have the same name.
deleteBeforeReplace :=
// 1. We know resource must be replaced.
// 1. We know resource must be replaced.
len(replaces) > 0 &&
// 2. Object is NOT autonamed (i.e., user manually named it, and therefore we can't
// auto-generate the name).
Expand Down

0 comments on commit a9083f2

Please sign in to comment.