-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add handling of updates to required fields to the CRD Upgrade Safety …
…preflight check Signed-off-by: Rashmi Gottipati <[email protected]>
- Loading branch information
1 parent
6321d10
commit 99a3981
Showing
6 changed files
with
509 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 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
130 changes: 130 additions & 0 deletions
130
test/e2e/preflight_crdupgradesafety_invalid_field_change_requiredfield_added_test.go
This file contains 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,130 @@ | ||
// Copyright 2024 The Carvel Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package e2e | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestPreflightCRDUpgradeSafetyInvalidFieldChangeRequiredFieldAdded(t *testing.T) { | ||
env := BuildEnv(t) | ||
logger := Logger{} | ||
kapp := Kapp{t, env.Namespace, env.KappBinaryPath, logger} | ||
kubectl := Kubectl{t, env.Namespace, logger} | ||
|
||
testName := "preflightcrdupgradesafetyinvalidfieldchangerequiredfieldadded" | ||
|
||
base := ` | ||
--- | ||
apiVersion: apiextensions.k8s.io/v1 | ||
kind: CustomResourceDefinition | ||
metadata: | ||
annotations: | ||
controller-gen.kubebuilder.io/version: v0.13.0 | ||
name: memcacheds.__test-name__.example.com | ||
spec: | ||
group: __test-name__.example.com | ||
names: | ||
kind: Memcached | ||
listKind: MemcachedList | ||
plural: memcacheds | ||
singular: memcached | ||
scope: Namespaced | ||
versions: | ||
- name: v1alpha1 | ||
schema: | ||
openAPIV3Schema: | ||
properties: | ||
apiVersion: | ||
type: string | ||
kind: | ||
type: string | ||
metadata: | ||
type: object | ||
spec: | ||
type: string | ||
properties: | ||
image: | ||
type: string | ||
pollInterval: | ||
type: string | ||
required: | ||
- image | ||
status: | ||
type: object | ||
type: object | ||
served: true | ||
storage: true | ||
subresources: | ||
status: {} | ||
` | ||
|
||
base = strings.ReplaceAll(base, "__test-name__", testName) | ||
appName := "preflight-crdupgradesafety-app" | ||
|
||
cleanUp := func() { | ||
kapp.Run([]string{"delete", "-a", appName}) | ||
RemoveClusterResource(t, "ns", testName, "", kubectl) | ||
} | ||
cleanUp() | ||
defer cleanUp() | ||
|
||
update := ` | ||
--- | ||
apiVersion: apiextensions.k8s.io/v1 | ||
kind: CustomResourceDefinition | ||
metadata: | ||
annotations: | ||
controller-gen.kubebuilder.io/version: v0.13.0 | ||
name: memcacheds.__test-name__.example.com | ||
spec: | ||
group: __test-name__.example.com | ||
names: | ||
kind: Memcached | ||
listKind: MemcachedList | ||
plural: memcacheds | ||
singular: memcached | ||
scope: Namespaced | ||
versions: | ||
- name: v1alpha1 | ||
schema: | ||
openAPIV3Schema: | ||
properties: | ||
apiVersion: | ||
type: string | ||
kind: | ||
type: string | ||
metadata: | ||
type: object | ||
spec: | ||
type: string | ||
properties: | ||
image: | ||
type: string | ||
pollInterval: | ||
type: string | ||
required: | ||
- image | ||
- pollInterval | ||
status: | ||
type: object | ||
type: object | ||
served: true | ||
storage: true | ||
subresources: | ||
status: {} | ||
` | ||
|
||
update = strings.ReplaceAll(update, "__test-name__", testName) | ||
logger.Section("deploy app with CRD update that adds a required field value, preflight check enabled, should error", func() { | ||
_, err := kapp.RunWithOpts([]string{"deploy", "-a", appName, "-f", "-"}, RunOpts{StdinReader: strings.NewReader(base)}) | ||
require.NoError(t, err) | ||
_, err = kapp.RunWithOpts([]string{"deploy", "--preflight=CRDUpgradeSafety", "-a", appName, "-f", "-"}, | ||
RunOpts{StdinReader: strings.NewReader(update), AllowError: true}) | ||
require.Error(t, err) | ||
}) | ||
} |
127 changes: 127 additions & 0 deletions
127
...light_crdupgradesafety_invalid_field_change_requiredfield_added_when_none_existed_test.go
This file contains 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,127 @@ | ||
// Copyright 2024 The Carvel Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package e2e | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestPreflightCRDUpgradeSafetyInvalidFieldChangeRequiredFieldAddedWhenNoneExisted(t *testing.T) { | ||
env := BuildEnv(t) | ||
logger := Logger{} | ||
kapp := Kapp{t, env.Namespace, env.KappBinaryPath, logger} | ||
kubectl := Kubectl{t, env.Namespace, logger} | ||
|
||
testName := "preflightcrdupgradesafetyinvalidfieldchangerequiredfieldaddedwhennonexisted" | ||
|
||
base := ` | ||
--- | ||
apiVersion: apiextensions.k8s.io/v1 | ||
kind: CustomResourceDefinition | ||
metadata: | ||
annotations: | ||
controller-gen.kubebuilder.io/version: v0.13.0 | ||
name: memcacheds.__test-name__.example.com | ||
spec: | ||
group: __test-name__.example.com | ||
names: | ||
kind: Memcached | ||
listKind: MemcachedList | ||
plural: memcacheds | ||
singular: memcached | ||
scope: Namespaced | ||
versions: | ||
- name: v1alpha1 | ||
schema: | ||
openAPIV3Schema: | ||
properties: | ||
apiVersion: | ||
type: string | ||
kind: | ||
type: string | ||
metadata: | ||
type: object | ||
spec: | ||
type: string | ||
properties: | ||
image: | ||
type: string | ||
pollInterval: | ||
type: string | ||
status: | ||
type: object | ||
type: object | ||
served: true | ||
storage: true | ||
subresources: | ||
status: {} | ||
` | ||
|
||
base = strings.ReplaceAll(base, "__test-name__", testName) | ||
appName := "preflight-crdupgradesafety-app" | ||
|
||
cleanUp := func() { | ||
kapp.Run([]string{"delete", "-a", appName}) | ||
RemoveClusterResource(t, "ns", testName, "", kubectl) | ||
} | ||
cleanUp() | ||
defer cleanUp() | ||
|
||
update := ` | ||
--- | ||
apiVersion: apiextensions.k8s.io/v1 | ||
kind: CustomResourceDefinition | ||
metadata: | ||
annotations: | ||
controller-gen.kubebuilder.io/version: v0.13.0 | ||
name: memcacheds.__test-name__.example.com | ||
spec: | ||
group: __test-name__.example.com | ||
names: | ||
kind: Memcached | ||
listKind: MemcachedList | ||
plural: memcacheds | ||
singular: memcached | ||
scope: Namespaced | ||
versions: | ||
- name: v1alpha1 | ||
schema: | ||
openAPIV3Schema: | ||
properties: | ||
apiVersion: | ||
type: string | ||
kind: | ||
type: string | ||
metadata: | ||
type: object | ||
spec: | ||
type: string | ||
properties: | ||
image: | ||
type: string | ||
pollInterval: | ||
type: string | ||
required: | ||
- image | ||
status: | ||
type: object | ||
type: object | ||
served: true | ||
storage: true | ||
subresources: | ||
status: {} | ||
` | ||
|
||
update = strings.ReplaceAll(update, "__test-name__", testName) | ||
logger.Section("deploy app with CRD update that adds a new required field value when none existed prior to this, preflight check enabled, should error", func() { | ||
_, err := kapp.RunWithOpts([]string{"deploy", "-a", appName, "-f", "-"}, RunOpts{StdinReader: strings.NewReader(base)}) | ||
require.NoError(t, err) | ||
_, err = kapp.RunWithOpts([]string{"deploy", "--preflight=CRDUpgradeSafety", "-a", appName, "-f", "-"}, | ||
RunOpts{StdinReader: strings.NewReader(update), AllowError: true}) | ||
require.Error(t, err) | ||
}) | ||
} |
Oops, something went wrong.