diff --git a/.github/workflows/test-gh-k8s-1.16.yml b/.github/workflows/test-gh-k8s-1.16.yml index 972e10a4e..4b0b3d4ca 100644 --- a/.github/workflows/test-gh-k8s-1.16.yml +++ b/.github/workflows/test-gh-k8s-1.16.yml @@ -34,9 +34,9 @@ jobs: wget -O- https://carvel.dev/install.sh | K14SIO_INSTALL_BIN_DIR=/tmp/bin bash - wget -O- https://github.com/kubernetes/minikube/releases/download/v1.10.0/minikube-linux-amd64 > /tmp/bin/minikube + wget -O- https://github.com/kubernetes/minikube/releases/download/v1.31.0/minikube-linux-amd64 > /tmp/bin/minikube chmod +x /tmp/bin/minikube - minikube start --driver=docker --kubernetes-version 1.16.0 + minikube start --driver=docker --kubernetes-version 1.21.6 eval $(minikube docker-env --shell=bash) # Ensure that there is no existing kapp installed diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..9e26dfeeb --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/pkg/kapp/clusterapply/add_or_update_change.go b/pkg/kapp/clusterapply/add_or_update_change.go index c569b8d29..bdc53cb28 100644 --- a/pkg/kapp/clusterapply/add_or_update_change.go +++ b/pkg/kapp/clusterapply/add_or_update_change.go @@ -12,6 +12,7 @@ import ( ctlres "github.com/vmware-tanzu/carvel-kapp/pkg/kapp/resources" "github.com/vmware-tanzu/carvel-kapp/pkg/kapp/util" "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/types" ) const ( @@ -252,7 +253,7 @@ func (c AddOrUpdateChange) recordAppliedResource(savedRes ctlres.Resource) error } // Record last applied change on the latest version of a resource - latestResWithHistoryUpdated, madeAnyModifications, err := latestResWithHistory.RecordLastAppliedResource(applyChange) + annotationStr, madeAnyModifications, err := latestResWithHistory.RecordLastAppliedResource(applyChange) if err != nil { return true, fmt.Errorf("Recording last applied resource: %w", err) } @@ -262,12 +263,14 @@ func (c AddOrUpdateChange) recordAppliedResource(savedRes ctlres.Resource) error return true, nil } - _, err = c.identifiedResources.Update(latestResWithHistoryUpdated) + jsonStr := fmt.Sprintf("{\"metadata\": {\"annotations\": %s }}", annotationStr) + data := []byte(jsonStr) + + _, err = c.identifiedResources.Patch(savedRes, types.MergePatchType, data) if err != nil { latestResWithHistory = nil // Get again return false, fmt.Errorf("Saving record of last applied resource: %w", err) } - return true, nil }) } diff --git a/pkg/kapp/diff/resource_with_history.go b/pkg/kapp/diff/resource_with_history.go index 34115aa7f..7d24f740d 100644 --- a/pkg/kapp/diff/resource_with_history.go +++ b/pkg/kapp/diff/resource_with_history.go @@ -4,6 +4,7 @@ package diff import ( + "encoding/json" "fmt" "os" @@ -68,13 +69,13 @@ func (r ResourceWithHistory) AllowsRecordingLastApplied() bool { return !found } -func (r ResourceWithHistory) RecordLastAppliedResource(appliedChange Change) (ctlres.Resource, bool, error) { +func (r ResourceWithHistory) RecordLastAppliedResource(appliedChange Change) (string, bool, error) { // Use compact representation to take as little space as possible // because annotation value max length is 262144 characters // (https://github.com/vmware-tanzu/carvel-kapp/issues/48). appliedResBytes, err := appliedChange.AppliedResource().AsCompactBytes() if err != nil { - return nil, true, err + return "", true, err } diff := appliedChange.OpsDiff() @@ -84,37 +85,30 @@ func (r ResourceWithHistory) RecordLastAppliedResource(appliedChange Change) (ct r.resource.Description(), diff.MinimalMD5(), diff.MinimalString()) } - annsMod := ctlres.StringMapAppendMod{ - ResourceMatcher: ctlres.AllMatcher{}, - Path: ctlres.NewPathFromStrings([]string{"metadata", "annotations"}), - KVs: map[string]string{ - appliedResAnnKey: string(appliedResBytes), - appliedResDiffMD5AnnKey: diff.MinimalMD5(), + annsKVS := map[string]string{ + appliedResAnnKey: string(appliedResBytes), + appliedResDiffMD5AnnKey: diff.MinimalMD5(), - // Following fields useful for debugging: - // debugAppliedResDiffAnnKey: diff.MinimalString(), - // debugAppliedResDiffFullAnnKey: diff.FullString(), - }, + // Following fields useful for debugging: + // debugAppliedResDiffAnnKey: diff.MinimalString(), + // debugAppliedResDiffFullAnnKey: diff.FullString(), } const annValMaxLen = 262144 // kapp deploy should work without adding disable annotation when annotation value max length exceed // (https://github.com/vmware-tanzu/carvel-kapp/issues/410) - for _, annVal := range annsMod.KVs { + for _, annVal := range annsKVS { if len(annVal) > annValMaxLen { - return nil, false, nil + return "", false, nil } } - resultRes := r.resource.DeepCopy() - - err = annsMod.Apply(resultRes) + result, err := json.Marshal(annsKVS) if err != nil { - return nil, true, err + return "", false, err } - - return resultRes, true, nil + return string(result), true, nil } func (r ResourceWithHistory) CalculateChange(appliedRes ctlres.Resource) (Change, error) { diff --git a/test/e2e/ignore_failing_api_services_flag_test.go b/test/e2e/ignore_failing_api_services_flag_test.go index 27a176509..db81ad3d2 100644 --- a/test/e2e/ignore_failing_api_services_flag_test.go +++ b/test/e2e/ignore_failing_api_services_flag_test.go @@ -4,6 +4,7 @@ package e2e import ( + "fmt" "strings" "testing" @@ -15,6 +16,7 @@ func TestIgnoreFailingAPIServices(t *testing.T) { env := BuildEnv(t) logger := Logger{} kapp := Kapp{t, env.Namespace, env.KappBinaryPath, logger} + kubectl := Kubectl{t, env.Namespace, logger} yaml1 := ` --- @@ -125,9 +127,23 @@ metadata: }) logger.Section("deploy app that uses failing api service", func() { - _, err := kapp.RunWithOpts([]string{"deploy", "-f", "-", "-a", name3}, RunOpts{ + + out, err := kubectl.RunWithOpts([]string{"get", "apiservice"}, RunOpts{ + AllowError: true}) + + fmt.Printf(" \n =========> Out: %+v", out) + fmt.Printf("\n ==========> err: %+v", err) + + // out, err = kubectl.RunWithOpts([]string{"apply", "-f", "-"}, RunOpts{ + // AllowError: true, IntoNs: true, StdinReader: strings.NewReader(yaml3)}) + + out, err = kapp.RunWithOpts([]string{"deploy", "-f", "-", "-a", name3}, RunOpts{ AllowError: true, IntoNs: true, StdinReader: strings.NewReader(yaml3)}) - require.Errorf(t, err, "Expected error when deploying with failing api service") + + fmt.Printf(" \n =========> Out: %+v", out) + fmt.Printf("\n ==========> err: %+v", err) + fmt.Printf("\n ==========> err.Error(): %+s", err.Error()) + require.Errorf(t, err, "Expected error when deploying with failing api serviceeasouckweg") require.Contains(t, err.Error(), "unable to retrieve the complete list of server APIs: samplekapptest.com/v1", "Expected api retrieval error")