1
0
mirror of https://github.com/ko-build/ko.git synced 2025-07-09 23:45:49 +02:00

remove deprecated k8s flags support (#750)

This commit is contained in:
Jason Hall
2022-07-13 16:29:54 -04:00
committed by GitHub
parent 8f228585b9
commit ca1648dcbf
7 changed files with 42 additions and 247 deletions

View File

@ -45,44 +45,26 @@ ko apply -f FILENAME [flags]
### Options
```
--as string Username to impersonate for the operation (DEPRECATED)
--as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups. (DEPRECATED)
--bare Whether to just use KO_DOCKER_REPO without additional context (may not work properly with --tags).
-B, --base-import-paths Whether to use the base path without MD5 hash after KO_DOCKER_REPO (may not work properly with --tags).
--cache-dir string Default cache directory (DEPRECATED)
--certificate-authority string Path to a cert file for the certificate authority (DEPRECATED)
--client-certificate string Path to a client certificate file for TLS (DEPRECATED)
--client-key string Path to a client key file for TLS (DEPRECATED)
--cluster string The name of the kubeconfig cluster to use (DEPRECATED)
--context string The name of the kubeconfig context to use (DEPRECATED)
--disable-optimizations Disable optimizations when building Go code. Useful when you want to interactively debug the created container.
-f, --filename strings Filename, directory, or URL to files to use to create the resource
-h, --help help for apply
--image-label strings Which labels (key=value) to add to the image.
--image-refs string Path to file where a list of the published image references will be written.
--insecure-registry Whether to skip TLS verification on the registry
--insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure (DEPRECATED)
-j, --jobs int The maximum number of concurrent builds (default GOMAXPROCS)
--kubeconfig string Path to the kubeconfig file to use for CLI requests. (DEPRECATED)
-L, --local Load into images to local docker daemon.
-n, --namespace string If present, the namespace scope for this CLI request (DEPRECATED)
--oci-layout-path string Path to save the OCI image layout of the built images
--password string Password for basic authentication to the API server (DEPRECATED)
--platform strings Which platform to use when pulling a multi-platform base. Format: all | <os>[/<arch>[/<variant>]][,platform]*
-P, --preserve-import-paths Whether to preserve the full import path after KO_DOCKER_REPO.
--push Push images to KO_DOCKER_REPO (default true)
-R, --recursive Process the directory used in -f, --filename recursively. Useful when you want to manage related manifests organized within the same directory.
--request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (DEPRECATED)
--sbom string The SBOM media type to use (none will disable SBOM synthesis and upload, also supports: spdx, cyclonedx, go.version-m). (default "spdx")
-l, --selector string Selector (label query) to filter on, supports '=', '==', and '!='.(e.g. -l key1=value1,key2=value2)
-s, --server string The address and port of the Kubernetes API server (DEPRECATED)
--tag-only Include tags but not digests in resolved image references. Useful when digests are not preserved when images are repopulated.
-t, --tags strings Which tags to use for the produced image instead of the default 'latest' tag (may not work properly with --base-import-paths or --bare). (default [latest])
--tarball string File to save images tarballs
--tls-server-name string Server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used (DEPRECATED)
--token string Bearer token for authentication to the API server (DEPRECATED)
--user string The name of the kubeconfig user to use (DEPRECATED)
--username string Username for basic authentication to the API server (DEPRECATED)
--bare Whether to just use KO_DOCKER_REPO without additional context (may not work properly with --tags).
-B, --base-import-paths Whether to use the base path without MD5 hash after KO_DOCKER_REPO (may not work properly with --tags).
--disable-optimizations Disable optimizations when building Go code. Useful when you want to interactively debug the created container.
-f, --filename strings Filename, directory, or URL to files to use to create the resource
-h, --help help for apply
--image-label strings Which labels (key=value) to add to the image.
--image-refs string Path to file where a list of the published image references will be written.
--insecure-registry Whether to skip TLS verification on the registry
-j, --jobs int The maximum number of concurrent builds (default GOMAXPROCS)
-L, --local Load into images to local docker daemon.
--oci-layout-path string Path to save the OCI image layout of the built images
--platform strings Which platform to use when pulling a multi-platform base. Format: all | <os>[/<arch>[/<variant>]][,platform]*
-P, --preserve-import-paths Whether to preserve the full import path after KO_DOCKER_REPO.
--push Push images to KO_DOCKER_REPO (default true)
-R, --recursive Process the directory used in -f, --filename recursively. Useful when you want to manage related manifests organized within the same directory.
--sbom string The SBOM media type to use (none will disable SBOM synthesis and upload, also supports: spdx, cyclonedx, go.version-m). (default "spdx")
-l, --selector string Selector (label query) to filter on, supports '=', '==', and '!='.(e.g. -l key1=value1,key2=value2)
--tag-only Include tags but not digests in resolved image references. Useful when digests are not preserved when images are repopulated.
-t, --tags strings Which tags to use for the produced image instead of the default 'latest' tag (may not work properly with --base-import-paths or --bare). (default [latest])
--tarball string File to save images tarballs
```
### Options inherited from parent commands

View File

@ -45,44 +45,26 @@ ko create -f FILENAME [flags]
### Options
```
--as string Username to impersonate for the operation (DEPRECATED)
--as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups. (DEPRECATED)
--bare Whether to just use KO_DOCKER_REPO without additional context (may not work properly with --tags).
-B, --base-import-paths Whether to use the base path without MD5 hash after KO_DOCKER_REPO (may not work properly with --tags).
--cache-dir string Default cache directory (DEPRECATED)
--certificate-authority string Path to a cert file for the certificate authority (DEPRECATED)
--client-certificate string Path to a client certificate file for TLS (DEPRECATED)
--client-key string Path to a client key file for TLS (DEPRECATED)
--cluster string The name of the kubeconfig cluster to use (DEPRECATED)
--context string The name of the kubeconfig context to use (DEPRECATED)
--disable-optimizations Disable optimizations when building Go code. Useful when you want to interactively debug the created container.
-f, --filename strings Filename, directory, or URL to files to use to create the resource
-h, --help help for create
--image-label strings Which labels (key=value) to add to the image.
--image-refs string Path to file where a list of the published image references will be written.
--insecure-registry Whether to skip TLS verification on the registry
--insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure (DEPRECATED)
-j, --jobs int The maximum number of concurrent builds (default GOMAXPROCS)
--kubeconfig string Path to the kubeconfig file to use for CLI requests. (DEPRECATED)
-L, --local Load into images to local docker daemon.
-n, --namespace string If present, the namespace scope for this CLI request (DEPRECATED)
--oci-layout-path string Path to save the OCI image layout of the built images
--password string Password for basic authentication to the API server (DEPRECATED)
--platform strings Which platform to use when pulling a multi-platform base. Format: all | <os>[/<arch>[/<variant>]][,platform]*
-P, --preserve-import-paths Whether to preserve the full import path after KO_DOCKER_REPO.
--push Push images to KO_DOCKER_REPO (default true)
-R, --recursive Process the directory used in -f, --filename recursively. Useful when you want to manage related manifests organized within the same directory.
--request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (DEPRECATED)
--sbom string The SBOM media type to use (none will disable SBOM synthesis and upload, also supports: spdx, cyclonedx, go.version-m). (default "spdx")
-l, --selector string Selector (label query) to filter on, supports '=', '==', and '!='.(e.g. -l key1=value1,key2=value2)
-s, --server string The address and port of the Kubernetes API server (DEPRECATED)
--tag-only Include tags but not digests in resolved image references. Useful when digests are not preserved when images are repopulated.
-t, --tags strings Which tags to use for the produced image instead of the default 'latest' tag (may not work properly with --base-import-paths or --bare). (default [latest])
--tarball string File to save images tarballs
--tls-server-name string Server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used (DEPRECATED)
--token string Bearer token for authentication to the API server (DEPRECATED)
--user string The name of the kubeconfig user to use (DEPRECATED)
--username string Username for basic authentication to the API server (DEPRECATED)
--bare Whether to just use KO_DOCKER_REPO without additional context (may not work properly with --tags).
-B, --base-import-paths Whether to use the base path without MD5 hash after KO_DOCKER_REPO (may not work properly with --tags).
--disable-optimizations Disable optimizations when building Go code. Useful when you want to interactively debug the created container.
-f, --filename strings Filename, directory, or URL to files to use to create the resource
-h, --help help for create
--image-label strings Which labels (key=value) to add to the image.
--image-refs string Path to file where a list of the published image references will be written.
--insecure-registry Whether to skip TLS verification on the registry
-j, --jobs int The maximum number of concurrent builds (default GOMAXPROCS)
-L, --local Load into images to local docker daemon.
--oci-layout-path string Path to save the OCI image layout of the built images
--platform strings Which platform to use when pulling a multi-platform base. Format: all | <os>[/<arch>[/<variant>]][,platform]*
-P, --preserve-import-paths Whether to preserve the full import path after KO_DOCKER_REPO.
--push Push images to KO_DOCKER_REPO (default true)
-R, --recursive Process the directory used in -f, --filename recursively. Useful when you want to manage related manifests organized within the same directory.
--sbom string The SBOM media type to use (none will disable SBOM synthesis and upload, also supports: spdx, cyclonedx, go.version-m). (default "spdx")
-l, --selector string Selector (label query) to filter on, supports '=', '==', and '!='.(e.g. -l key1=value1,key2=value2)
--tag-only Include tags but not digests in resolved image references. Useful when digests are not preserved when images are repopulated.
-t, --tags strings Which tags to use for the produced image instead of the default 'latest' tag (may not work properly with --base-import-paths or --bare). (default [latest])
--tarball string File to save images tarballs
```
### Options inherited from parent commands

1
go.mod
View File

@ -26,7 +26,6 @@ require (
github.com/sigstore/cosign v1.9.0
github.com/sigstore/rekor v0.7.0 // indirect
github.com/spf13/cobra v1.5.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.12.0
go.mongodb.org/mongo-driver v1.9.1 // indirect
go.uber.org/automaxprocs v1.5.1

View File

@ -1,125 +0,0 @@
// Copyright 2021 Google LLC All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package internal
import (
"strings"
"github.com/spf13/pflag"
)
// AddFlags adds kubectl global flags to the given flagset.
func AddFlags(f *KubectlFlags, flags *pflag.FlagSet) {
flags.StringVar(&f.kubeConfig, "kubeconfig", "", "Path to the kubeconfig file to use for CLI requests. (DEPRECATED)")
flags.StringVar(&f.cacheDir, "cache-dir", "", "Default cache directory (DEPRECATED)")
flags.StringVar(&f.certFile, "client-certificate", "", "Path to a client certificate file for TLS (DEPRECATED)")
flags.StringVar(&f.keyFile, "client-key", "", "Path to a client key file for TLS (DEPRECATED)")
flags.StringVar(&f.bearerToken, "token", "", "Bearer token for authentication to the API server (DEPRECATED)")
flags.StringVar(&f.impersonate, "as", "", "Username to impersonate for the operation (DEPRECATED)")
flags.StringArrayVar(&f.impersonateGroup, "as-group", []string{}, "Group to impersonate for the operation, this flag can be repeated to specify multiple groups. (DEPRECATED)")
flags.StringVar(&f.username, "username", "", "Username for basic authentication to the API server (DEPRECATED)")
flags.StringVar(&f.password, "password", "", "Password for basic authentication to the API server (DEPRECATED)")
flags.StringVar(&f.clusterName, "cluster", "", "The name of the kubeconfig cluster to use (DEPRECATED)")
flags.StringVar(&f.authInfoName, "user", "", "The name of the kubeconfig user to use (DEPRECATED)")
flags.StringVarP(&f.namespace, "namespace", "n", "", "If present, the namespace scope for this CLI request (DEPRECATED)")
flags.StringVar(&f.context, "context", "", "The name of the kubeconfig context to use (DEPRECATED)")
flags.StringVarP(&f.apiServer, "server", "s", "", "The address and port of the Kubernetes API server (DEPRECATED)")
flags.StringVar(&f.tlsServerName, "tls-server-name", "", "Server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used (DEPRECATED)")
flags.BoolVar(&f.insecure, "insecure-skip-tls-verify", false, "If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure (DEPRECATED)")
flags.StringVar(&f.caFile, "certificate-authority", "", "Path to a cert file for the certificate authority (DEPRECATED)")
flags.StringVar(&f.timeout, "request-timeout", "", "The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (DEPRECATED)")
}
// KubectlFlags holds kubectl global flag values as parsed from flags.
type KubectlFlags struct {
kubeConfig string
cacheDir string
certFile string
keyFile string
bearerToken string
impersonate string
impersonateGroup []string
username string
password string
clusterName string
authInfoName string
context string
namespace string
apiServer string
tlsServerName string
insecure bool
caFile string
timeout string
}
// Values returns a slice of flag values to pass to kubectl.
func (f KubectlFlags) Values() []string {
var v []string
if f.kubeConfig != "" {
v = append(v, "--kubeconfig="+f.kubeConfig)
}
if f.cacheDir != "" {
v = append(v, "--cache-dir="+f.cacheDir)
}
if f.certFile != "" {
v = append(v, "--client-certificate="+f.certFile)
}
if f.keyFile != "" {
v = append(v, "--client-key="+f.keyFile)
}
if f.bearerToken != "" {
v = append(v, "--token="+f.bearerToken)
}
if f.impersonate != "" {
v = append(v, "--as="+f.impersonate)
}
if len(f.impersonateGroup) > 0 {
v = append(v, "--as-group="+strings.Join(f.impersonateGroup, ","))
}
if f.username != "" {
v = append(v, "--username="+f.username)
}
if f.password != "" {
v = append(v, "--password="+f.password)
}
if f.clusterName != "" {
v = append(v, "--cluster="+f.clusterName)
}
if f.authInfoName != "" {
v = append(v, "--user="+f.authInfoName)
}
if f.context != "" {
v = append(v, "--context="+f.context)
}
if f.namespace != "" {
v = append(v, "--namespace="+f.namespace)
}
if f.apiServer != "" {
v = append(v, "--server="+f.apiServer)
}
if f.tlsServerName != "" {
v = append(v, "--tls-server-name="+f.tlsServerName)
}
if f.insecure {
v = append(v, "--insecure=true")
}
if f.caFile != "" {
v = append(v, "--certificate-authority="+f.caFile)
}
if f.timeout != "" {
v = append(v, "--request-timeout="+f.timeout)
}
return v
}

View File

@ -17,35 +17,16 @@ package commands
import (
"errors"
"fmt"
"log"
"os"
"os/exec"
"strings"
"github.com/google/ko/internal"
"github.com/google/ko/pkg/commands/options"
"github.com/spf13/cobra"
"golang.org/x/sync/errgroup"
)
const kubectlFlagsWarningTemplate = `NOTICE!
-----------------------------------------------------------------
Passing kubectl global flags to ko directly is deprecated.
Instead of passing:
ko %s ... %s
Pass kubectl global flags separated by "--":
ko %s ... -- %s
For more information see:
https://github.com/google/ko/issues/317
-----------------------------------------------------------------
`
// addApply augments our CLI surface with apply.
func addApply(topLevel *cobra.Command) {
var kf internal.KubectlFlags
po := &options.PublishOptions{}
fo := &options.FilenameOptions{}
so := &options.SelectorOptions{}
@ -105,16 +86,7 @@ func addApply(topLevel *cobra.Command) {
// Issue a "kubectl apply" command reading from stdin,
// to which we will pipe the resolved files, and any
// remaining flags passed after '--'.
argv := []string{"apply", "-f", "-"}
if kflags := kf.Values(); len(kflags) != 0 {
skflags := strings.Join(kflags, " ")
log.Printf(kubectlFlagsWarningTemplate,
"apply", skflags,
"apply", skflags)
argv = append(argv, kflags...)
}
argv = append(argv, args...)
kubectlCmd := exec.CommandContext(ctx, "kubectl", argv...)
kubectlCmd := exec.CommandContext(ctx, "kubectl", append([]string{"apply", "-f", "-"}, args...)...)
// Pass through our environment
kubectlCmd.Env = os.Environ()
@ -160,7 +132,6 @@ func addApply(topLevel *cobra.Command) {
options.AddFileArg(apply, fo)
options.AddSelectorArg(apply, so)
options.AddBuildOptions(apply, bo)
internal.AddFlags(&kf, apply.Flags())
topLevel.AddCommand(apply)
}

View File

@ -17,12 +17,10 @@ package commands
import (
"errors"
"fmt"
"log"
"os"
"os/exec"
"strings"
"github.com/google/ko/internal"
"github.com/google/ko/pkg/commands/options"
"github.com/spf13/cobra"
"golang.org/x/sync/errgroup"
@ -30,7 +28,6 @@ import (
// addCreate augments our CLI surface with apply.
func addCreate(topLevel *cobra.Command) {
var kf internal.KubectlFlags
po := &options.PublishOptions{}
fo := &options.FilenameOptions{}
so := &options.SelectorOptions{}
@ -90,16 +87,7 @@ func addCreate(topLevel *cobra.Command) {
// Issue a "kubectl create" command reading from stdin,
// to which we will pipe the resolved files, and any
// remaining flags passed after '--'.
argv := []string{"create", "-f", "-"}
if kflags := kf.Values(); len(kflags) != 0 {
skflags := strings.Join(stripPassword(kflags), " ")
log.Printf(kubectlFlagsWarningTemplate,
"create", skflags,
"create", skflags)
argv = append(argv, kflags...)
}
argv = append(argv, args...)
kubectlCmd := exec.CommandContext(ctx, "kubectl", argv...)
kubectlCmd := exec.CommandContext(ctx, "kubectl", append([]string{"create", "-f", "-"}, args...)...)
// Pass through our environment
kubectlCmd.Env = os.Environ()
@ -145,7 +133,6 @@ func addCreate(topLevel *cobra.Command) {
options.AddFileArg(create, fo)
options.AddSelectorArg(create, so)
options.AddBuildOptions(create, bo)
internal.AddFlags(&kf, create.Flags())
topLevel.AddCommand(create)
}

1
vendor/modules.txt vendored
View File

@ -366,7 +366,6 @@ github.com/spf13/cobra/doc
# github.com/spf13/jwalterweatherman v1.1.0
github.com/spf13/jwalterweatherman
# github.com/spf13/pflag v1.0.5
## explicit
github.com/spf13/pflag
# github.com/spf13/viper v1.12.0
## explicit