-
Notifications
You must be signed in to change notification settings - Fork 1k
manifest: change computed_field
logic to mark all as unknown instead of only on changes
#2432
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
Open
BBBmau
wants to merge
15
commits into
main
Choose a base branch
from
computed_fields_allUnknown
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
aedb26d
fix crash when unexpeceted annotation appears
BBBmau a86a181
cleanup plan code and add computedFields test when setting computedFi…
BBBmau 5fd30f4
add changelog-entry
BBBmau b495d36
Merge branch 'main' into computed_fields_allUnknown
BBBmau f6f3f17
fix manifest tests
BBBmau d6dd7da
remove createNamespace
BBBmau dd0d50d
add TestKubernetesManifest_ComputedDeploymentFields
BBBmau d756ffb
add copyright header
BBBmau ee84da4
Merge branch 'main' into computed_fields_allUnknown
BBBmau 3368fd3
Update manifest/provider/apply.go
BBBmau bd56585
add findBackfillvalue
BBBmau 6cdde2c
add comment for findBackfillValue
BBBmau cca6249
Update manifest/test/acceptance/testdata/ComputedFields/computed_depl…
BBBmau f304b15
Merge branch 'main' into computed_fields_allUnknown
BBBmau e3b7aaf
err check
BBBmau File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:bug | ||
kubernetes_manifest: Fix unexpected annotation by setting values in `computed_fields` to be Unknown always | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
//go:build acceptance | ||
// +build acceptance | ||
|
||
package acceptance | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/hashicorp/go-hclog" | ||
"github.com/hashicorp/terraform-provider-kubernetes/manifest/provider" | ||
"github.com/hashicorp/terraform-provider-kubernetes/manifest/test/helper/kubernetes" | ||
tfstatehelper "github.com/hashicorp/terraform-provider-kubernetes/manifest/test/helper/state" | ||
) | ||
|
||
func TestKubernetesManifest_ComputedDeploymentFields(t *testing.T) { | ||
ctx := context.Background() | ||
|
||
reattachInfo, err := provider.ServeTest(ctx, hclog.Default(), t) | ||
if err != nil { | ||
t.Errorf("Failed to create provider instance: %q", err) | ||
} | ||
|
||
name := strings.ToLower(randName()) | ||
namespace := strings.ToLower(randName()) | ||
|
||
k8shelper.CreateNamespace(t, namespace) | ||
defer k8shelper.DeleteResource(t, namespace, kubernetes.NewGroupVersionResource("v1", "namespaces")) | ||
|
||
tfvars := TFVARS{ | ||
"name": name, | ||
"namespace": namespace, | ||
} | ||
|
||
tf := tfhelper.RequireNewWorkingDir(ctx, t) | ||
tf.SetReattachInfo(ctx, reattachInfo) | ||
defer func() { | ||
tf.Destroy(ctx) | ||
tf.Close() | ||
k8shelper.AssertNamespacedResourceDoesNotExist(t, "apps/v1", "deployments", namespace, name) | ||
}() | ||
|
||
tfconfig := loadTerraformConfig(t, "ComputedFields/computed_deployment.tf", tfvars) | ||
tf.SetConfig(ctx, string(tfconfig)) | ||
tf.Init(ctx) | ||
tf.Apply(ctx) | ||
|
||
s, err := tf.State(ctx) | ||
if err != nil { | ||
t.Fatalf("Failed to retrieve terraform state: %q", err) | ||
} | ||
tfstate := tfstatehelper.NewHelper(s) | ||
tfstate.AssertAttributeValues(t, tfstatehelper.AttributeValues{ | ||
"kubernetes_manifest.deployment_resource_diff.object.metadata.name": name, | ||
"kubernetes_manifest.deployment_resource_diff.object.metadata.namespace": namespace, | ||
"kubernetes_manifest.deployment_resource_diff.object.spec.template.spec.containers.0.resources.limits.cpu": "250m", | ||
"kubernetes_manifest.deployment_resource_diff.object.spec.template.spec.containers.0.resources.limits.memory": "512Mi", | ||
}) | ||
} |
52 changes: 52 additions & 0 deletions
52
manifest/test/acceptance/testdata/ComputedFields/computed_deployment.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
resource "kubernetes_manifest" "deployment_resource_diff" { | ||
computed_fields = ["spec.template.spec.containers[0].resources.limits[\"cpu\"]"] | ||
manifest = { | ||
apiVersion = "apps/v1" | ||
kind = "Deployment" | ||
|
||
metadata = { | ||
name = var.name | ||
namespace = var.namespace | ||
} | ||
|
||
spec = { | ||
replicas = 3 | ||
|
||
selector = { | ||
matchLabels = { | ||
test = "MyExampleApp" | ||
} | ||
} | ||
|
||
template = { | ||
metadata= { | ||
labels = { | ||
test = "MyExampleApp" | ||
} | ||
} | ||
|
||
|
||
spec = { | ||
containers = [{ | ||
image = "nginx:1.21.6" | ||
name = "example" | ||
|
||
resources = { | ||
limits = { | ||
cpu = "0.25" | ||
memory = "512Mi" | ||
} | ||
requests = { | ||
cpu = "250m" | ||
memory = "50Mi" | ||
} | ||
} | ||
}] | ||
} | ||
} | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.