Skip to content

Commit

Permalink
Updates migrate no ConfigMap error to be success
Browse files Browse the repository at this point in the history
  • Loading branch information
seans3 committed Dec 14, 2020
1 parent 57ea7e5 commit fa39a59
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
13 changes: 13 additions & 0 deletions commands/migratecmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/klog"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/util/i18n"
"sigs.k8s.io/cli-utils/pkg/common"
Expand Down Expand Up @@ -123,6 +124,12 @@ func (mr *MigrateRunner) Run(reader io.Reader, args []string) error {
// Retrieve the current ConfigMap inventory objects.
cmInvObj, err := mr.retrieveConfigMapInv(bytes.NewReader(stdinBytes), args)
if err != nil {
if _, ok := err.(inventory.NoInventoryObjError); ok {
// No ConfigMap inventory means the migration has already run before.
klog.V(4).Infoln("swallowing no ConfigMap inventory error")
return nil
}
klog.V(4).Infof("error retrieving ConfigMap inventory object: %s", err)
return err
}
cmObjs, err := mr.retrieveInvObjs(cmInvObj)
Expand Down Expand Up @@ -196,6 +203,12 @@ func (mr *MigrateRunner) retrieveConfigMapInv(reader io.Reader, args []string) (
return nil, err
}
cmInv, _, err := mr.cmLoader.InventoryInfo(objs)
if err != nil {
// No ConfigMap inventory means the migration has already run before.
if _, ok := err.(inventory.NoInventoryObjError); ok { //nolint
fmt.Fprintln(mr.ioStreams.Out, "no ConfigMap inventory...completed")
}
}
return cmInv, err
}

Expand Down
16 changes: 6 additions & 10 deletions e2e/live/end-to-end-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,12 @@ assertPodExists "pod-a" "test-rg-namespace"
assertPodExists "pod-b" "test-rg-namespace"
assertPodExists "pod-c" "test-rg-namespace"
assertRGInventory "test-rg-namespace"
# Run it again, and validate the output
${BIN_DIR}/kpt live migrate e2e/live/testdata/migrate-case-1a > $OUTPUT_DIR/status
assertContains "ensuring ResourceGroup CRD exists in cluster...already installed...success"
assertContains "updating Kptfile inventory values...values already exist...success"
assertContains "retrieve the current ConfigMap inventory...no ConfigMap inventory...completed"
assertContains "inventory migration...success"
printResult

# Test 9: kpt live preview with ResourceGroup inventory
Expand Down Expand Up @@ -545,7 +551,6 @@ assertPodNotExists "pod-c" "test-rg-namespace"
assertPodNotExists "pod-d" "test-rg-namespace"
printResult


# Test 12: kpt live init for Kptfile (ResourceGroup inventory)
# initial Kptfile does NOT have inventory info
cp -f e2e/live/testdata/Kptfile e2e/live/testdata/migrate-error
Expand All @@ -560,15 +565,6 @@ assertContains "name: inventory-"
assertContains "inventoryID:"
printResult

# Test 13: kpt live migrate with missing inventory-template.yaml should fail
# "migrate-error" directory does not have an inventory-template.yaml
echo "Testing kpt live migrate with missing inventory-template.yaml should fail"
echo "kpt live migrate e2e/live/testdata/migrate-error"
rm -f e2e/live/testdata/migrate-error/inventory-template.yaml
${BIN_DIR}/kpt live migrate e2e/live/testdata/migrate-error > $OUTPUT_DIR/status 2>&1
assertContains "inventory migration...failed"
printResult

# Test 14: kpt live migrate with no objects in cluster
# Add inventory-template.yaml to "migrate-error", but there are no objects in cluster.
cp -f e2e/live/testdata/inventory-template.yaml e2e/live/testdata/migrate-error
Expand Down

0 comments on commit fa39a59

Please sign in to comment.