diff --git a/go.mod b/go.mod index 344bbc6286..ad16269775 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,6 @@ require ( github.com/gorilla/websocket v1.5.3 github.com/hashicorp/go-version v1.7.0 github.com/karrick/tparse/v2 v2.8.2 - github.com/kubernetes-client/go-base v0.0.0-20190205182333-3d0e39759d98 github.com/mattn/go-colorable v0.1.13 github.com/mattn/go-isatty v0.0.20 github.com/moby/buildkit v0.13.2 diff --git a/go.sum b/go.sum index 67e7cd58c3..b79aeaa6b4 100644 --- a/go.sum +++ b/go.sum @@ -344,8 +344,6 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/kubernetes-client/go-base v0.0.0-20190205182333-3d0e39759d98 h1:ZMIkOkl/Bg5H4EJI7zbjVXAo4rV0QJOGz2U5A0xUmZU= -github.com/kubernetes-client/go-base v0.0.0-20190205182333-3d0e39759d98/go.mod h1:HPlr4uJEfrxar3JUY9cmXs3oooPjTLO6nEaEAIt5LI8= github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ= diff --git a/internal/namespaces/k8s/v1/custom_kubeconfig_get.go b/internal/namespaces/k8s/v1/custom_kubeconfig_get.go index e99ffe0e74..5df9064a2b 100644 --- a/internal/namespaces/k8s/v1/custom_kubeconfig_get.go +++ b/internal/namespaces/k8s/v1/custom_kubeconfig_get.go @@ -5,8 +5,8 @@ import ( "reflect" "github.com/ghodss/yaml" - api "github.com/kubernetes-client/go-base/config/api" "github.com/scaleway/scaleway-cli/v2/internal/core" + api "github.com/scaleway/scaleway-cli/v2/internal/namespaces/k8s/v1/types" k8s "github.com/scaleway/scaleway-sdk-go/api/k8s/v1" "github.com/scaleway/scaleway-sdk-go/scw" ) diff --git a/internal/namespaces/k8s/v1/custom_kubeconfig_get_test.go b/internal/namespaces/k8s/v1/custom_kubeconfig_get_test.go index 46c7fbe34f..952187ac3c 100644 --- a/internal/namespaces/k8s/v1/custom_kubeconfig_get_test.go +++ b/internal/namespaces/k8s/v1/custom_kubeconfig_get_test.go @@ -5,9 +5,9 @@ import ( "github.com/alecthomas/assert" "github.com/ghodss/yaml" - api "github.com/kubernetes-client/go-base/config/api" "github.com/scaleway/scaleway-cli/v2/internal/core" "github.com/scaleway/scaleway-cli/v2/internal/namespaces/k8s/v1" + api "github.com/scaleway/scaleway-cli/v2/internal/namespaces/k8s/v1/types" ) func Test_GetKubeconfig(t *testing.T) { diff --git a/internal/namespaces/k8s/v1/custom_kubeconfig_helpers.go b/internal/namespaces/k8s/v1/custom_kubeconfig_helpers.go index f3f07e2f5e..8b2cf9b75c 100644 --- a/internal/namespaces/k8s/v1/custom_kubeconfig_helpers.go +++ b/internal/namespaces/k8s/v1/custom_kubeconfig_helpers.go @@ -8,8 +8,8 @@ import ( "strings" "github.com/ghodss/yaml" - api "github.com/kubernetes-client/go-base/config/api" "github.com/scaleway/scaleway-cli/v2/internal/core" + api "github.com/scaleway/scaleway-cli/v2/internal/namespaces/k8s/v1/types" ) // get the path to the wanted kubeconfig on disk diff --git a/internal/namespaces/k8s/v1/custom_kubeconfig_install.go b/internal/namespaces/k8s/v1/custom_kubeconfig_install.go index 4e69f970d3..7368396bb4 100644 --- a/internal/namespaces/k8s/v1/custom_kubeconfig_install.go +++ b/internal/namespaces/k8s/v1/custom_kubeconfig_install.go @@ -8,8 +8,8 @@ import ( "reflect" "github.com/ghodss/yaml" - api "github.com/kubernetes-client/go-base/config/api" "github.com/scaleway/scaleway-cli/v2/internal/core" + api "github.com/scaleway/scaleway-cli/v2/internal/namespaces/k8s/v1/types" k8s "github.com/scaleway/scaleway-sdk-go/api/k8s/v1" "github.com/scaleway/scaleway-sdk-go/scw" ) diff --git a/internal/namespaces/k8s/v1/custom_kubeconfig_install_test.go b/internal/namespaces/k8s/v1/custom_kubeconfig_install_test.go index 866443ab4b..c533c67da3 100644 --- a/internal/namespaces/k8s/v1/custom_kubeconfig_install_test.go +++ b/internal/namespaces/k8s/v1/custom_kubeconfig_install_test.go @@ -7,9 +7,9 @@ import ( "github.com/alecthomas/assert" "github.com/ghodss/yaml" - api "github.com/kubernetes-client/go-base/config/api" "github.com/scaleway/scaleway-cli/v2/internal/core" "github.com/scaleway/scaleway-cli/v2/internal/namespaces/k8s/v1" + api "github.com/scaleway/scaleway-cli/v2/internal/namespaces/k8s/v1/types" k8sSDK "github.com/scaleway/scaleway-sdk-go/api/k8s/v1" ) diff --git a/internal/namespaces/k8s/v1/custom_kubeconfig_uninstall.go b/internal/namespaces/k8s/v1/custom_kubeconfig_uninstall.go index c544ae0e8c..68ef4afb92 100644 --- a/internal/namespaces/k8s/v1/custom_kubeconfig_uninstall.go +++ b/internal/namespaces/k8s/v1/custom_kubeconfig_uninstall.go @@ -7,8 +7,8 @@ import ( "reflect" "strings" - "github.com/kubernetes-client/go-base/config/api" "github.com/scaleway/scaleway-cli/v2/internal/core" + api "github.com/scaleway/scaleway-cli/v2/internal/namespaces/k8s/v1/types" ) type k8sKubeconfigUninstallRequest struct { diff --git a/internal/namespaces/k8s/v1/custom_kubeconfig_uninstall_test.go b/internal/namespaces/k8s/v1/custom_kubeconfig_uninstall_test.go index 3ddf59ef3d..c10b0aa99f 100644 --- a/internal/namespaces/k8s/v1/custom_kubeconfig_uninstall_test.go +++ b/internal/namespaces/k8s/v1/custom_kubeconfig_uninstall_test.go @@ -7,9 +7,9 @@ import ( "github.com/alecthomas/assert" "github.com/ghodss/yaml" - api "github.com/kubernetes-client/go-base/config/api" "github.com/scaleway/scaleway-cli/v2/internal/core" "github.com/scaleway/scaleway-cli/v2/internal/namespaces/k8s/v1" + api "github.com/scaleway/scaleway-cli/v2/internal/namespaces/k8s/v1/types" k8sSDK "github.com/scaleway/scaleway-sdk-go/api/k8s/v1" ) diff --git a/internal/namespaces/k8s/v1/helpers_test.go b/internal/namespaces/k8s/v1/helpers_test.go index 9361a09a95..0dd3779efb 100644 --- a/internal/namespaces/k8s/v1/helpers_test.go +++ b/internal/namespaces/k8s/v1/helpers_test.go @@ -6,8 +6,8 @@ import ( "strings" "github.com/ghodss/yaml" - go_api "github.com/kubernetes-client/go-base/config/api" "github.com/scaleway/scaleway-cli/v2/internal/core" + go_api "github.com/scaleway/scaleway-cli/v2/internal/namespaces/k8s/v1/types" k8s "github.com/scaleway/scaleway-sdk-go/api/k8s/v1" ) diff --git a/internal/namespaces/k8s/v1/types/types.go b/internal/namespaces/k8s/v1/types/types.go new file mode 100644 index 0000000000..622c06559d --- /dev/null +++ b/internal/namespaces/k8s/v1/types/types.go @@ -0,0 +1,271 @@ +/* +Copyright 2014 The Kubernetes Authors. + +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 types + +// NOTE: This Config type definition is copied from k8s.io/client-go/tools/clientcmd/api/v1/types.go +// for parsing the kube config yaml. The "k8s.io/apimachinery/pkg/runtime" dependency has +// been removed. + +// Where possible, json tags match the cli argument names. +// Top level config objects and all values required for proper functioning are not "omitempty". Any truly optional piece of config is allowed to be omitted. + +// Config holds the information needed to build connect to remote kubernetes clusters as a given user +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +type Config struct { + // Legacy field from pkg/api/types.go TypeMeta. + // TODO(jlowdermilk): remove this after eliminating downstream dependencies. + // +k8s:conversion-gen=false + // +optional + Kind string `json:"kind,omitempty"` + // Legacy field from pkg/api/types.go TypeMeta. + // TODO(jlowdermilk): remove this after eliminating downstream dependencies. + // +k8s:conversion-gen=false + // +optional + APIVersion string `json:"apiVersion,omitempty"` + // Preferences holds general information to be use for cli interactions + Preferences Preferences `json:"preferences"` + // Clusters is a map of referencable names to cluster configs + Clusters []NamedCluster `json:"clusters"` + // AuthInfos is a map of referencable names to user configs + AuthInfos []NamedAuthInfo `json:"users"` + // Contexts is a map of referencable names to context configs + Contexts []NamedContext `json:"contexts"` + // CurrentContext is the name of the context that you would like to use by default + CurrentContext string `json:"current-context"` + // Extensions holds additional information. This is useful for extenders so that reads and writes don't clobber unknown fields + // +optional + Extensions []NamedExtension `json:"extensions,omitempty"` +} + +type Preferences struct { + // +optional + Colors bool `json:"colors,omitempty"` + // Extensions holds additional information. This is useful for extenders so that reads and writes don't clobber unknown fields + // +optional + Extensions []NamedExtension `json:"extensions,omitempty"` +} + +// Cluster contains information about how to communicate with a kubernetes cluster +type Cluster struct { + // Server is the address of the kubernetes cluster (https://hostname:port). + Server string `json:"server"` + // TLSServerName is used to check server certificate. If TLSServerName is empty, the hostname used to contact the server is used. + // +optional + TLSServerName string `json:"tls-server-name,omitempty"` + // InsecureSkipTLSVerify skips the validity check for the server's certificate. This will make your HTTPS connections insecure. + // +optional + InsecureSkipTLSVerify bool `json:"insecure-skip-tls-verify,omitempty"` + // CertificateAuthority is the path to a cert file for the certificate authority. + // +optional + CertificateAuthority string `json:"certificate-authority,omitempty"` + // CertificateAuthorityData contains PEM-encoded certificate authority certificates. Overrides CertificateAuthority + // +optional + CertificateAuthorityData []byte `json:"certificate-authority-data,omitempty"` + // ProxyURL is the URL to the proxy to be used for all requests made by this + // client. URLs with "http", "https", and "socks5" schemes are supported. If + // this configuration is not provided or the empty string, the client + // attempts to construct a proxy configuration from http_proxy and + // https_proxy environment variables. If these environment variables are not + // set, the client does not attempt to proxy requests. + // + // socks5 proxying does not currently support spdy streaming endpoints (exec, + // attach, port forward). + // +optional + ProxyURL string `json:"proxy-url,omitempty"` + // DisableCompression allows client to opt-out of response compression for all requests to the server. This is useful + // to speed up requests (specifically lists) when client-server network bandwidth is ample, by saving time on + // compression (server-side) and decompression (client-side): https://github.com/kubernetes/kubernetes/issues/112296. + // +optional + DisableCompression bool `json:"disable-compression,omitempty"` + // Extensions holds additional information. This is useful for extenders so that reads and writes don't clobber unknown fields + // +optional + Extensions []NamedExtension `json:"extensions,omitempty"` +} + +// AuthInfo contains information that describes identity information. This is use to tell the kubernetes cluster who you are. +type AuthInfo struct { + // ClientCertificate is the path to a client cert file for TLS. + // +optional + ClientCertificate string `json:"client-certificate,omitempty"` + // ClientCertificateData contains PEM-encoded data from a client cert file for TLS. Overrides ClientCertificate + // +optional + ClientCertificateData []byte `json:"client-certificate-data,omitempty"` + // ClientKey is the path to a client key file for TLS. + // +optional + ClientKey string `json:"client-key,omitempty"` + // ClientKeyData contains PEM-encoded data from a client key file for TLS. Overrides ClientKey + // +optional + ClientKeyData []byte `json:"client-key-data,omitempty" datapolicy:"security-key"` + // Token is the bearer token for authentication to the kubernetes cluster. + // +optional + Token string `json:"token,omitempty" datapolicy:"token"` + // TokenFile is a pointer to a file that contains a bearer token (as described above). If both Token and TokenFile are present, Token takes precedence. + // +optional + TokenFile string `json:"tokenFile,omitempty"` + // Impersonate is the username to impersonate. The name matches the flag. + // +optional + Impersonate string `json:"as,omitempty"` + // ImpersonateUID is the uid to impersonate. + // +optional + ImpersonateUID string `json:"as-uid,omitempty"` + // ImpersonateGroups is the groups to impersonate. + // +optional + ImpersonateGroups []string `json:"as-groups,omitempty"` + // ImpersonateUserExtra contains additional information for impersonated user. + // +optional + ImpersonateUserExtra map[string][]string `json:"as-user-extra,omitempty"` + // Username is the username for basic authentication to the kubernetes cluster. + // +optional + Username string `json:"username,omitempty"` + // Password is the password for basic authentication to the kubernetes cluster. + // +optional + Password string `json:"password,omitempty" datapolicy:"password"` + // AuthProvider specifies a custom authentication plugin for the kubernetes cluster. + // +optional + AuthProvider *AuthProviderConfig `json:"auth-provider,omitempty"` + // Exec specifies a custom exec-based authentication plugin for the kubernetes cluster. + // +optional + Exec *ExecConfig `json:"exec,omitempty"` + // Extensions holds additional information. This is useful for extenders so that reads and writes don't clobber unknown fields + // +optional + Extensions []NamedExtension `json:"extensions,omitempty"` +} + +// Context is a tuple of references to a cluster (how do I communicate with a kubernetes cluster), a user (how do I identify myself), and a namespace (what subset of resources do I want to work with) +type Context struct { + // Cluster is the name of the cluster for this context + Cluster string `json:"cluster"` + // AuthInfo is the name of the authInfo for this context + AuthInfo string `json:"user"` + // Namespace is the default namespace to use on unspecified requests + // +optional + Namespace string `json:"namespace,omitempty"` + // Extensions holds additional information. This is useful for extenders so that reads and writes don't clobber unknown fields + // +optional + Extensions []NamedExtension `json:"extensions,omitempty"` +} + +// NamedCluster relates nicknames to cluster information +type NamedCluster struct { + // Name is the nickname for this Cluster + Name string `json:"name"` + // Cluster holds the cluster information + Cluster Cluster `json:"cluster"` +} + +// NamedContext relates nicknames to context information +type NamedContext struct { + // Name is the nickname for this Context + Name string `json:"name"` + // Context holds the context information + Context Context `json:"context"` +} + +// NamedAuthInfo relates nicknames to auth information +type NamedAuthInfo struct { + // Name is the nickname for this AuthInfo + Name string `json:"name"` + // AuthInfo holds the auth information + AuthInfo AuthInfo `json:"user"` +} + +// NamedExtension relates nicknames to extension information +type NamedExtension struct { + // Name is the nickname for this Extension + Name string `json:"name"` + // Extension holds the extension information + Extension interface{} `json:"extension"` +} + +// AuthProviderConfig holds the configuration for a specified auth provider. +type AuthProviderConfig struct { + Name string `json:"name"` + Config map[string]string `json:"config"` +} + +// ExecConfig specifies a command to provide client credentials. The command is exec'd +// and outputs structured stdout holding credentials. +// +// See the client.authentication.k8s.io API group for specifications of the exact input +// and output format +type ExecConfig struct { + // Command to execute. + Command string `json:"command"` + // Arguments to pass to the command when executing it. + // +optional + Args []string `json:"args"` + // Env defines additional environment variables to expose to the process. These + // are unioned with the host's environment, as well as variables client-go uses + // to pass argument to the plugin. + // +optional + Env []ExecEnvVar `json:"env"` + + // Preferred input version of the ExecInfo. The returned ExecCredentials MUST use + // the same encoding version as the input. + APIVersion string `json:"apiVersion,omitempty"` + + // This text is shown to the user when the executable doesn't seem to be + // present. For example, `brew install foo-cli` might be a good InstallHint for + // foo-cli on Mac OS systems. + InstallHint string `json:"installHint,omitempty"` + + // ProvideClusterInfo determines whether or not to provide cluster information, + // which could potentially contain very large CA data, to this exec plugin as a + // part of the KUBERNETES_EXEC_INFO environment variable. By default, it is set + // to false. Package k8s.io/client-go/tools/auth/exec provides helper methods for + // reading this environment variable. + ProvideClusterInfo bool `json:"provideClusterInfo"` + + // InteractiveMode determines this plugin's relationship with standard input. Valid + // values are "Never" (this exec plugin never uses standard input), "IfAvailable" (this + // exec plugin wants to use standard input if it is available), or "Always" (this exec + // plugin requires standard input to function). See ExecInteractiveMode values for more + // details. + // + // If APIVersion is client.authentication.k8s.io/v1alpha1 or + // client.authentication.k8s.io/v1beta1, then this field is optional and defaults + // to "IfAvailable" when unset. Otherwise, this field is required. + //+optional + InteractiveMode ExecInteractiveMode `json:"interactiveMode,omitempty"` +} + +// ExecEnvVar is used for setting environment variables when executing an exec-based +// credential plugin. +type ExecEnvVar struct { + Name string `json:"name"` + Value string `json:"value"` +} + +// ExecInteractiveMode is a string that describes an exec plugin's relationship with standard input. +type ExecInteractiveMode string + +const ( + // NeverExecInteractiveMode declares that this exec plugin never needs to use standard + // input, and therefore the exec plugin will be run regardless of whether standard input is + // available for user input. + NeverExecInteractiveMode ExecInteractiveMode = "Never" + // IfAvailableExecInteractiveMode declares that this exec plugin would like to use standard input + // if it is available, but can still operate if standard input is not available. Therefore, the + // exec plugin will be run regardless of whether stdin is available for user input. If standard + // input is available for user input, then it will be provided to this exec plugin. + IfAvailableExecInteractiveMode ExecInteractiveMode = "IfAvailable" + // AlwaysExecInteractiveMode declares that this exec plugin requires standard input in order to + // run, and therefore the exec plugin will only be run if standard input is available for user + // input. If standard input is not available for user input, then the exec plugin will not be run + // and an error will be returned by the exec plugin runner. + AlwaysExecInteractiveMode ExecInteractiveMode = "Always" +) diff --git a/internal/namespaces/lb/v1/helper_test.go b/internal/namespaces/lb/v1/helper_test.go index f8e7667564..9b0562550e 100644 --- a/internal/namespaces/lb/v1/helper_test.go +++ b/internal/namespaces/lb/v1/helper_test.go @@ -7,8 +7,8 @@ import ( "time" "github.com/ghodss/yaml" - go_api "github.com/kubernetes-client/go-base/config/api" "github.com/scaleway/scaleway-cli/v2/internal/core" + go_api "github.com/scaleway/scaleway-cli/v2/internal/namespaces/k8s/v1/types" "github.com/scaleway/scaleway-sdk-go/api/k8s/v1" "github.com/scaleway/scaleway-sdk-go/api/lb/v1" )