mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
Merge pull request #62196 from liggitt/create-dry-run
Automatic merge from submit-queue (batch tested with PRs 60900, 62215, 62196). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Remove need for server connections for dry-run create when running create commands in --dry-run mode, we don't need a server connection or restmapper information ```release-note NONE ```
This commit is contained in:
commit
dfd6f581b5
@ -2387,11 +2387,12 @@ run_secrets_test() {
|
|||||||
create_and_use_new_namespace
|
create_and_use_new_namespace
|
||||||
kube::log::status "Testing secrets"
|
kube::log::status "Testing secrets"
|
||||||
|
|
||||||
# Ensure dry run succeeds and includes kind, apiVersion and data
|
# Ensure dry run succeeds and includes kind, apiVersion and data, and doesn't require a server connection
|
||||||
output_message=$(kubectl create secret generic test --from-literal=key1=value1 --dry-run -o yaml)
|
output_message=$(kubectl create secret generic test --from-literal=key1=value1 --dry-run -o yaml --server=example.com --v=6)
|
||||||
kube::test::if_has_string "${output_message}" 'kind: Secret'
|
kube::test::if_has_string "${output_message}" 'kind: Secret'
|
||||||
kube::test::if_has_string "${output_message}" 'apiVersion: v1'
|
kube::test::if_has_string "${output_message}" 'apiVersion: v1'
|
||||||
kube::test::if_has_string "${output_message}" 'key1: dmFsdWUx'
|
kube::test::if_has_string "${output_message}" 'key1: dmFsdWUx'
|
||||||
|
kube::test::if_has_not_string "${output_message}" 'example.com'
|
||||||
|
|
||||||
### Create a new namespace
|
### Create a new namespace
|
||||||
# Pre-condition: the test-secrets namespace does not exist
|
# Pre-condition: the test-secrets namespace does not exist
|
||||||
|
@ -315,6 +315,7 @@ func RunCreateSubcommand(f cmdutil.Factory, cmd *cobra.Command, out io.Writer, o
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
mapper, typer := f.Object()
|
mapper, typer := f.Object()
|
||||||
|
if !options.DryRun {
|
||||||
gvks, _, err := typer.ObjectKinds(obj)
|
gvks, _, err := typer.ObjectKinds(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -342,7 +343,6 @@ func RunCreateSubcommand(f cmdutil.Factory, cmd *cobra.Command, out io.Writer, o
|
|||||||
}
|
}
|
||||||
obj = info.Object
|
obj = info.Object
|
||||||
|
|
||||||
if !options.DryRun {
|
|
||||||
obj, err = resource.NewHelper(client, mapping).Create(namespace, false, info.Object)
|
obj, err = resource.NewHelper(client, mapping).Create(namespace, false, info.Object)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -354,7 +354,7 @@ func RunCreateSubcommand(f cmdutil.Factory, cmd *cobra.Command, out io.Writer, o
|
|||||||
}
|
}
|
||||||
|
|
||||||
if useShortOutput := options.OutputFormat == "name"; useShortOutput || len(options.OutputFormat) == 0 {
|
if useShortOutput := options.OutputFormat == "name"; useShortOutput || len(options.OutputFormat) == 0 {
|
||||||
cmdutil.PrintSuccess(useShortOutput, out, info.Object, options.DryRun, "created")
|
cmdutil.PrintSuccess(useShortOutput, out, obj, options.DryRun, "created")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user