From b49ba16c073e4b2502cde6a32d3d30253014a4f6 Mon Sep 17 00:00:00 2001 From: Antonin Stefanutti Date: Thu, 17 Feb 2022 18:26:48 +0100 Subject: [PATCH] chore: Update vendor directory --- .../camel-k/pkg/apis/camel/v1/build_types.go | 25 +- .../camel-k/pkg/apis/camel/v1/common_types.go | 30 -- .../camel/v1/integrationplatform_types.go | 1 - .../camel-k/pkg/apis/camel/v1/maven_types.go | 39 ++- .../apis/camel/v1/zz_generated.deepcopy.go | 26 +- vendor/k8s.io/kubectl/LICENSE | 201 ++++++++++++ vendor/k8s.io/kubectl/pkg/cmd/set/env/doc.go | 18 ++ .../kubectl/pkg/cmd/set/env/env_parse.go | 140 +++++++++ .../kubectl/pkg/cmd/set/env/env_resolve.go | 297 ++++++++++++++++++ vendor/modules.txt | 3 + 10 files changed, 732 insertions(+), 48 deletions(-) create mode 100644 vendor/k8s.io/kubectl/LICENSE create mode 100644 vendor/k8s.io/kubectl/pkg/cmd/set/env/doc.go create mode 100644 vendor/k8s.io/kubectl/pkg/cmd/set/env/env_parse.go create mode 100644 vendor/k8s.io/kubectl/pkg/cmd/set/env/env_resolve.go diff --git a/vendor/github.com/apache/camel-k/pkg/apis/camel/v1/build_types.go b/vendor/github.com/apache/camel-k/pkg/apis/camel/v1/build_types.go index 7345702439..8b8d35acba 100644 --- a/vendor/github.com/apache/camel-k/pkg/apis/camel/v1/build_types.go +++ b/vendor/github.com/apache/camel-k/pkg/apis/camel/v1/build_types.go @@ -62,10 +62,17 @@ type BuilderTask struct { Resources []ResourceSpec `json:"resources,omitempty"` Dependencies []string `json:"dependencies,omitempty"` Steps []string `json:"steps,omitempty"` - Maven MavenSpec `json:"maven,omitempty"` + Maven MavenBuildSpec `json:"maven,omitempty"` BuildDir string `json:"buildDir,omitempty"` } +// MavenBuildSpec -- +type MavenBuildSpec struct { + MavenSpec `json:",inline"` + // The Maven repositories. + Repositories []Repository `json:"repositories,omitempty"` +} + // PublishTask -- type PublishTask struct { ContextDir string `json:"contextDir,omitempty"` @@ -76,19 +83,17 @@ type PublishTask struct { // BuildahTask -- type BuildahTask struct { - BaseTask `json:",inline"` - PublishTask `json:",inline"` - Verbose *bool `json:"verbose,omitempty"` - HttpProxySecret string `json:"httpProxySecret,omitempty"` + BaseTask `json:",inline"` + PublishTask `json:",inline"` + Verbose *bool `json:"verbose,omitempty"` } // KanikoTask -- type KanikoTask struct { - BaseTask `json:",inline"` - PublishTask `json:",inline"` - Verbose *bool `json:"verbose,omitempty"` - HttpProxySecret string `json:"httpProxySecret,omitempty"` - Cache KanikoTaskCache `json:"cache,omitempty"` + BaseTask `json:",inline"` + PublishTask `json:",inline"` + Verbose *bool `json:"verbose,omitempty"` + Cache KanikoTaskCache `json:"cache,omitempty"` } // KanikoTaskCache -- diff --git a/vendor/github.com/apache/camel-k/pkg/apis/camel/v1/common_types.go b/vendor/github.com/apache/camel-k/pkg/apis/camel/v1/common_types.go index 34e4074b5c..9880081c50 100644 --- a/vendor/github.com/apache/camel-k/pkg/apis/camel/v1/common_types.go +++ b/vendor/github.com/apache/camel-k/pkg/apis/camel/v1/common_types.go @@ -98,29 +98,6 @@ type Configurable interface { Configurations() []ConfigurationSpec } -// MavenSpec -- -type MavenSpec struct { - // The path of the local Maven repository. - LocalRepository string `json:"localRepository,omitempty"` - // The Maven properties. - Properties map[string]string `json:"properties,omitempty"` - // A reference to the ConfigMap or Secret key that contains - // the Maven settings. - Settings ValueSource `json:"settings,omitempty"` - // The Secret name and key, containing the CA certificate(s) used to connect - // to remote Maven repositories. - // It can contain X.509 certificates, and PKCS#7 formatted certificate chains. - // A JKS formatted keystore is automatically created to store the CA certificate(s), - // and configured to be used as a trusted certificate(s) by the Maven commands. - // Note that the root CA certificates are also imported into the created keystore. - CASecret *corev1.SecretKeySelector `json:"caSecret,omitempty"` - // Deprecated: use IntegrationPlatform.Spec.Build.Timeout instead - Timeout *metav1.Duration `json:"timeout,omitempty"` - Repositories []Repository `json:"repositories,omitempty"` - // Maven build extensions https://maven.apache.org/guides/mini/guide-using-extensions.html - Extension []MavenArtifact `json:"extension,omitempty"` -} - // RegistrySpec provides the configuration for the container registry type RegistrySpec struct { Insecure bool `json:"insecure,omitempty"` @@ -138,13 +115,6 @@ type ValueSource struct { SecretKeyRef *corev1.SecretKeySelector `json:"secretKeyRef,omitempty"` } -// MavenArtifact -- -type MavenArtifact struct { - GroupID string `json:"groupId" yaml:"groupId" xml:"groupId"` - ArtifactID string `json:"artifactId" yaml:"artifactId" xml:"artifactId"` - Version string `json:"version,omitempty" yaml:"version,omitempty" xml:"version,omitempty"` -} - // RuntimeSpec -- type RuntimeSpec struct { Version string `json:"version" yaml:"version"` diff --git a/vendor/github.com/apache/camel-k/pkg/apis/camel/v1/integrationplatform_types.go b/vendor/github.com/apache/camel-k/pkg/apis/camel/v1/integrationplatform_types.go index 1468e4bba1..ba6fa32a0c 100644 --- a/vendor/github.com/apache/camel-k/pkg/apis/camel/v1/integrationplatform_types.go +++ b/vendor/github.com/apache/camel-k/pkg/apis/camel/v1/integrationplatform_types.go @@ -115,7 +115,6 @@ type IntegrationPlatformBuildSpec struct { Timeout *metav1.Duration `json:"timeout,omitempty"` PersistentVolumeClaim string `json:"persistentVolumeClaim,omitempty"` Maven MavenSpec `json:"maven,omitempty"` - HTTPProxySecret string `json:"httpProxySecret,omitempty"` KanikoBuildCache *bool `json:"kanikoBuildCache,omitempty"` } diff --git a/vendor/github.com/apache/camel-k/pkg/apis/camel/v1/maven_types.go b/vendor/github.com/apache/camel-k/pkg/apis/camel/v1/maven_types.go index 426f113d14..569336c5e1 100644 --- a/vendor/github.com/apache/camel-k/pkg/apis/camel/v1/maven_types.go +++ b/vendor/github.com/apache/camel-k/pkg/apis/camel/v1/maven_types.go @@ -17,7 +17,35 @@ limitations under the License. package v1 -// Repository -- +import ( + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// MavenSpec -- +type MavenSpec struct { + // The path of the local Maven repository. + LocalRepository string `json:"localRepository,omitempty"` + // The Maven properties. + Properties map[string]string `json:"properties,omitempty"` + // A reference to the ConfigMap or Secret key that contains + // the Maven settings. + Settings ValueSource `json:"settings,omitempty"` + // The Secret name and key, containing the CA certificate(s) used to connect + // to remote Maven repositories. + // It can contain X.509 certificates, and PKCS#7 formatted certificate chains. + // A JKS formatted keystore is automatically created to store the CA certificate(s), + // and configured to be used as a trusted certificate(s) by the Maven commands. + // Note that the root CA certificates are also imported into the created keystore. + CASecret *corev1.SecretKeySelector `json:"caSecret,omitempty"` + // Deprecated: use IntegrationPlatform.Spec.Build.Timeout instead + Timeout *metav1.Duration `json:"timeout,omitempty"` + // The Maven build extensions. + // See https://maven.apache.org/guides/mini/guide-using-extensions.html. + Extension []MavenArtifact `json:"extension,omitempty"` +} + +// Repository defines a Maven repository type Repository struct { ID string `xml:"id" json:"id"` Name string `xml:"name,omitempty" json:"name,omitempty"` @@ -26,9 +54,16 @@ type Repository struct { Releases RepositoryPolicy `xml:"releases,omitempty" json:"releases,omitempty"` } -// RepositoryPolicy -- +// RepositoryPolicy defines the policy associated to a Maven repository type RepositoryPolicy struct { Enabled bool `xml:"enabled" json:"enabled"` UpdatePolicy string `xml:"updatePolicy,omitempty" json:"updatePolicy,omitempty"` ChecksumPolicy string `xml:"checksumPolicy,omitempty" json:"checksumPolicy,omitempty"` } + +// MavenArtifact defines a Maven artifact +type MavenArtifact struct { + GroupID string `json:"groupId" yaml:"groupId" xml:"groupId"` + ArtifactID string `json:"artifactId" yaml:"artifactId" xml:"artifactId"` + Version string `json:"version,omitempty" yaml:"version,omitempty" xml:"version,omitempty"` +} diff --git a/vendor/github.com/apache/camel-k/pkg/apis/camel/v1/zz_generated.deepcopy.go b/vendor/github.com/apache/camel-k/pkg/apis/camel/v1/zz_generated.deepcopy.go index bc44413c51..7bfdcd44ea 100644 --- a/vendor/github.com/apache/camel-k/pkg/apis/camel/v1/zz_generated.deepcopy.go +++ b/vendor/github.com/apache/camel-k/pkg/apis/camel/v1/zz_generated.deepcopy.go @@ -1231,6 +1231,27 @@ func (in *MavenArtifact) DeepCopy() *MavenArtifact { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *MavenBuildSpec) DeepCopyInto(out *MavenBuildSpec) { + *out = *in + in.MavenSpec.DeepCopyInto(&out.MavenSpec) + if in.Repositories != nil { + in, out := &in.Repositories, &out.Repositories + *out = make([]Repository, len(*in)) + copy(*out, *in) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MavenBuildSpec. +func (in *MavenBuildSpec) DeepCopy() *MavenBuildSpec { + if in == nil { + return nil + } + out := new(MavenBuildSpec) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *MavenSpec) DeepCopyInto(out *MavenSpec) { *out = *in @@ -1252,11 +1273,6 @@ func (in *MavenSpec) DeepCopyInto(out *MavenSpec) { *out = new(metav1.Duration) **out = **in } - if in.Repositories != nil { - in, out := &in.Repositories, &out.Repositories - *out = make([]Repository, len(*in)) - copy(*out, *in) - } if in.Extension != nil { in, out := &in.Extension, &out.Extension *out = make([]MavenArtifact, len(*in)) diff --git a/vendor/k8s.io/kubectl/LICENSE b/vendor/k8s.io/kubectl/LICENSE new file mode 100644 index 0000000000..8dada3edaf --- /dev/null +++ b/vendor/k8s.io/kubectl/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + 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. diff --git a/vendor/k8s.io/kubectl/pkg/cmd/set/env/doc.go b/vendor/k8s.io/kubectl/pkg/cmd/set/env/doc.go new file mode 100644 index 0000000000..25e4c04a70 --- /dev/null +++ b/vendor/k8s.io/kubectl/pkg/cmd/set/env/doc.go @@ -0,0 +1,18 @@ +/* +Copyright 2017 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 env provides functions to incorporate environment variables into set env. +package env diff --git a/vendor/k8s.io/kubectl/pkg/cmd/set/env/env_parse.go b/vendor/k8s.io/kubectl/pkg/cmd/set/env/env_parse.go new file mode 100644 index 0000000000..d5b3ec7061 --- /dev/null +++ b/vendor/k8s.io/kubectl/pkg/cmd/set/env/env_parse.go @@ -0,0 +1,140 @@ +/* +Copyright 2017 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 env + +import ( + "bufio" + "fmt" + "io" + "regexp" + "strings" + + "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/util/sets" +) + +var argumentEnvironment = regexp.MustCompile("(?ms)^(.+)\\=(.*)$") +var validArgumentEnvironment = regexp.MustCompile("(?ms)^(\\w+)\\=(.*)$") + +// IsEnvironmentArgument checks whether a string is an environment argument, that is, whether it matches the "anycharacters=anycharacters" pattern. +func IsEnvironmentArgument(s string) bool { + return argumentEnvironment.MatchString(s) +} + +// IsValidEnvironmentArgument checks whether a string is a valid environment argument, that is, whether it matches the "wordcharacters=anycharacters" pattern. Word characters can be letters, numbers, and underscores. +func IsValidEnvironmentArgument(s string) bool { + return validArgumentEnvironment.MatchString(s) +} + +// SplitEnvironmentFromResources separates resources from environment arguments. +// Resources must come first. Arguments may have the "DASH-" syntax. +func SplitEnvironmentFromResources(args []string) (resources, envArgs []string, ok bool) { + first := true + for _, s := range args { + // this method also has to understand env removal syntax, i.e. KEY- + isEnv := IsEnvironmentArgument(s) || strings.HasSuffix(s, "-") + switch { + case first && isEnv: + first = false + fallthrough + case !first && isEnv: + envArgs = append(envArgs, s) + case first && !isEnv: + resources = append(resources, s) + case !first && !isEnv: + return nil, nil, false + } + } + return resources, envArgs, true +} + +// parseIntoEnvVar parses the list of key-value pairs into kubernetes EnvVar. +// envVarType is for making errors more specific to user intentions. +func parseIntoEnvVar(spec []string, defaultReader io.Reader, envVarType string) ([]v1.EnvVar, []string, error) { + env := []v1.EnvVar{} + exists := sets.NewString() + var remove []string + for _, envSpec := range spec { + switch { + case !IsValidEnvironmentArgument(envSpec) && !strings.HasSuffix(envSpec, "-"): + return nil, nil, fmt.Errorf("%ss must be of the form key=value and can only contain letters, numbers, and underscores", envVarType) + case envSpec == "-": + if defaultReader == nil { + return nil, nil, fmt.Errorf("when '-' is used, STDIN must be open") + } + fileEnv, err := readEnv(defaultReader, envVarType) + if err != nil { + return nil, nil, err + } + env = append(env, fileEnv...) + case strings.Contains(envSpec, "="): + parts := strings.SplitN(envSpec, "=", 2) + if len(parts) != 2 { + return nil, nil, fmt.Errorf("invalid %s: %v", envVarType, envSpec) + } + exists.Insert(parts[0]) + env = append(env, v1.EnvVar{ + Name: parts[0], + Value: parts[1], + }) + case strings.HasSuffix(envSpec, "-"): + remove = append(remove, envSpec[:len(envSpec)-1]) + default: + return nil, nil, fmt.Errorf("unknown %s: %v", envVarType, envSpec) + } + } + for _, removeLabel := range remove { + if _, found := exists[removeLabel]; found { + return nil, nil, fmt.Errorf("can not both modify and remove the same %s in the same command", envVarType) + } + } + return env, remove, nil +} + +// ParseEnv parses the elements of the first argument looking for environment variables in key=value form and, if one of those values is "-", it also scans the reader. +// The same environment variable cannot be both modified and removed in the same command. +func ParseEnv(spec []string, defaultReader io.Reader) ([]v1.EnvVar, []string, error) { + return parseIntoEnvVar(spec, defaultReader, "environment variable") +} + +func readEnv(r io.Reader, envVarType string) ([]v1.EnvVar, error) { + env := []v1.EnvVar{} + scanner := bufio.NewScanner(r) + for scanner.Scan() { + envSpec := scanner.Text() + if pos := strings.Index(envSpec, "#"); pos != -1 { + envSpec = envSpec[:pos] + } + + if strings.Contains(envSpec, "=") { + parts := strings.SplitN(envSpec, "=", 2) + if len(parts) != 2 { + return nil, fmt.Errorf("invalid %s: %v", envVarType, envSpec) + } + env = append(env, v1.EnvVar{ + Name: parts[0], + Value: parts[1], + }) + } + } + + if err := scanner.Err(); err != nil && err != io.EOF { + return nil, err + } + + return env, nil +} diff --git a/vendor/k8s.io/kubectl/pkg/cmd/set/env/env_resolve.go b/vendor/k8s.io/kubectl/pkg/cmd/set/env/env_resolve.go new file mode 100644 index 0000000000..e45b686b39 --- /dev/null +++ b/vendor/k8s.io/kubectl/pkg/cmd/set/env/env_resolve.go @@ -0,0 +1,297 @@ +/* +Copyright 2017 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 env + +import ( + "context" + "fmt" + "math" + "strconv" + "strings" + + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/meta" + "k8s.io/apimachinery/pkg/api/resource" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/util/sets" + "k8s.io/apimachinery/pkg/util/validation" + "k8s.io/client-go/kubernetes" +) + +// ResourceStore defines a new resource store data structure. +type ResourceStore struct { + SecretStore map[string]*corev1.Secret + ConfigMapStore map[string]*corev1.ConfigMap +} + +// NewResourceStore returns a pointer to a new resource store data structure. +func NewResourceStore() *ResourceStore { + return &ResourceStore{ + SecretStore: make(map[string]*corev1.Secret), + ConfigMapStore: make(map[string]*corev1.ConfigMap), + } +} + +// getSecretRefValue returns the value of a secret in the supplied namespace +func getSecretRefValue(client kubernetes.Interface, namespace string, store *ResourceStore, secretSelector *corev1.SecretKeySelector) (string, error) { + secret, ok := store.SecretStore[secretSelector.Name] + if !ok { + var err error + secret, err = client.CoreV1().Secrets(namespace).Get(context.TODO(), secretSelector.Name, metav1.GetOptions{}) + if err != nil { + return "", err + } + store.SecretStore[secretSelector.Name] = secret + } + if data, ok := secret.Data[secretSelector.Key]; ok { + return string(data), nil + } + return "", fmt.Errorf("key %s not found in secret %s", secretSelector.Key, secretSelector.Name) + +} + +// getConfigMapRefValue returns the value of a configmap in the supplied namespace +func getConfigMapRefValue(client kubernetes.Interface, namespace string, store *ResourceStore, configMapSelector *corev1.ConfigMapKeySelector) (string, error) { + configMap, ok := store.ConfigMapStore[configMapSelector.Name] + if !ok { + var err error + configMap, err = client.CoreV1().ConfigMaps(namespace).Get(context.TODO(), configMapSelector.Name, metav1.GetOptions{}) + if err != nil { + return "", err + } + store.ConfigMapStore[configMapSelector.Name] = configMap + } + if data, ok := configMap.Data[configMapSelector.Key]; ok { + return string(data), nil + } + return "", fmt.Errorf("key %s not found in config map %s", configMapSelector.Key, configMapSelector.Name) +} + +// getFieldRef returns the value of the supplied path in the given object +func getFieldRef(obj runtime.Object, from *corev1.EnvVarSource) (string, error) { + return extractFieldPathAsString(obj, from.FieldRef.FieldPath) +} + +// extractFieldPathAsString extracts the field from the given object +// and returns it as a string. The object must be a pointer to an +// API type. +func extractFieldPathAsString(obj interface{}, fieldPath string) (string, error) { + accessor, err := meta.Accessor(obj) + if err != nil { + return "", nil + } + + if path, subscript, ok := splitMaybeSubscriptedPath(fieldPath); ok { + switch path { + case "metadata.annotations": + if errs := validation.IsQualifiedName(strings.ToLower(subscript)); len(errs) != 0 { + return "", fmt.Errorf("invalid key subscript in %s: %s", fieldPath, strings.Join(errs, ";")) + } + return accessor.GetAnnotations()[subscript], nil + case "metadata.labels": + if errs := validation.IsQualifiedName(subscript); len(errs) != 0 { + return "", fmt.Errorf("invalid key subscript in %s: %s", fieldPath, strings.Join(errs, ";")) + } + return accessor.GetLabels()[subscript], nil + default: + return "", fmt.Errorf("fieldPath %q does not support subscript", fieldPath) + } + } + + switch fieldPath { + case "metadata.annotations": + return formatMap(accessor.GetAnnotations()), nil + case "metadata.labels": + return formatMap(accessor.GetLabels()), nil + case "metadata.name": + return accessor.GetName(), nil + case "metadata.namespace": + return accessor.GetNamespace(), nil + case "metadata.uid": + return string(accessor.GetUID()), nil + } + + return "", fmt.Errorf("unsupported fieldPath: %v", fieldPath) +} + +// splitMaybeSubscriptedPath checks whether the specified fieldPath is +// subscripted, and +// - if yes, this function splits the fieldPath into path and subscript, and +// returns (path, subscript, true). +// - if no, this function returns (fieldPath, "", false). +// +// Example inputs and outputs: +// - "metadata.annotations['myKey']" --> ("metadata.annotations", "myKey", true) +// - "metadata.annotations['a[b]c']" --> ("metadata.annotations", "a[b]c", true) +// - "metadata.labels['']" --> ("metadata.labels", "", true) +// - "metadata.labels" --> ("metadata.labels", "", false) +func splitMaybeSubscriptedPath(fieldPath string) (string, string, bool) { + if !strings.HasSuffix(fieldPath, "']") { + return fieldPath, "", false + } + s := strings.TrimSuffix(fieldPath, "']") + parts := strings.SplitN(s, "['", 2) + if len(parts) < 2 { + return fieldPath, "", false + } + if len(parts[0]) == 0 { + return fieldPath, "", false + } + return parts[0], parts[1], true +} + +// formatMap formats map[string]string to a string. +func formatMap(m map[string]string) (fmtStr string) { + // output with keys in sorted order to provide stable output + keys := sets.NewString() + for key := range m { + keys.Insert(key) + } + for _, key := range keys.List() { + fmtStr += fmt.Sprintf("%v=%q\n", key, m[key]) + } + fmtStr = strings.TrimSuffix(fmtStr, "\n") + + return +} + +// getResourceFieldRef returns the value of a resource in the given container +func getResourceFieldRef(from *corev1.EnvVarSource, container *corev1.Container) (string, error) { + return extractContainerResourceValue(from.ResourceFieldRef, container) +} + +// ExtractContainerResourceValue extracts the value of a resource +// in an already known container +func extractContainerResourceValue(fs *corev1.ResourceFieldSelector, container *corev1.Container) (string, error) { + divisor := resource.Quantity{} + if divisor.Cmp(fs.Divisor) == 0 { + divisor = resource.MustParse("1") + } else { + divisor = fs.Divisor + } + + switch fs.Resource { + case "limits.cpu": + return convertResourceCPUToString(container.Resources.Limits.Cpu(), divisor) + case "limits.memory": + return convertResourceMemoryToString(container.Resources.Limits.Memory(), divisor) + case "limits.ephemeral-storage": + return convertResourceEphemeralStorageToString(container.Resources.Limits.StorageEphemeral(), divisor) + case "requests.cpu": + return convertResourceCPUToString(container.Resources.Requests.Cpu(), divisor) + case "requests.memory": + return convertResourceMemoryToString(container.Resources.Requests.Memory(), divisor) + case "requests.ephemeral-storage": + return convertResourceEphemeralStorageToString(container.Resources.Requests.StorageEphemeral(), divisor) + } + // handle extended standard resources with dynamic names + // example: requests.hugepages- or limits.hugepages- + if strings.HasPrefix(fs.Resource, "requests.") { + resourceName := corev1.ResourceName(strings.TrimPrefix(fs.Resource, "requests.")) + if IsHugePageResourceName(resourceName) { + return convertResourceHugePagesToString(container.Resources.Requests.Name(resourceName, resource.BinarySI), divisor) + } + } + if strings.HasPrefix(fs.Resource, "limits.") { + resourceName := corev1.ResourceName(strings.TrimPrefix(fs.Resource, "limits.")) + if IsHugePageResourceName(resourceName) { + return convertResourceHugePagesToString(container.Resources.Limits.Name(resourceName, resource.BinarySI), divisor) + } + } + return "", fmt.Errorf("Unsupported container resource : %v", fs.Resource) +} + +// convertResourceCPUToString converts cpu value to the format of divisor and returns +// ceiling of the value. +func convertResourceCPUToString(cpu *resource.Quantity, divisor resource.Quantity) (string, error) { + c := int64(math.Ceil(float64(cpu.MilliValue()) / float64(divisor.MilliValue()))) + return strconv.FormatInt(c, 10), nil +} + +// convertResourceMemoryToString converts memory value to the format of divisor and returns +// ceiling of the value. +func convertResourceMemoryToString(memory *resource.Quantity, divisor resource.Quantity) (string, error) { + m := int64(math.Ceil(float64(memory.Value()) / float64(divisor.Value()))) + return strconv.FormatInt(m, 10), nil +} + +// convertResourceHugePagesToString converts hugepages value to the format of divisor and returns +// ceiling of the value. +func convertResourceHugePagesToString(hugePages *resource.Quantity, divisor resource.Quantity) (string, error) { + m := int64(math.Ceil(float64(hugePages.Value()) / float64(divisor.Value()))) + return strconv.FormatInt(m, 10), nil +} + +// convertResourceEphemeralStorageToString converts ephemeral storage value to the format of divisor and returns +// ceiling of the value. +func convertResourceEphemeralStorageToString(ephemeralStorage *resource.Quantity, divisor resource.Quantity) (string, error) { + m := int64(math.Ceil(float64(ephemeralStorage.Value()) / float64(divisor.Value()))) + return strconv.FormatInt(m, 10), nil +} + +// GetEnvVarRefValue returns the value referenced by the supplied EnvVarSource given the other supplied information. +func GetEnvVarRefValue(kc kubernetes.Interface, ns string, store *ResourceStore, from *corev1.EnvVarSource, obj runtime.Object, c *corev1.Container) (string, error) { + if from.SecretKeyRef != nil { + return getSecretRefValue(kc, ns, store, from.SecretKeyRef) + } + + if from.ConfigMapKeyRef != nil { + return getConfigMapRefValue(kc, ns, store, from.ConfigMapKeyRef) + } + + if from.FieldRef != nil { + return getFieldRef(obj, from) + } + + if from.ResourceFieldRef != nil { + return getResourceFieldRef(from, c) + } + + return "", fmt.Errorf("invalid valueFrom") +} + +// GetEnvVarRefString returns a text description of whichever field is set within the supplied EnvVarSource argument. +func GetEnvVarRefString(from *corev1.EnvVarSource) string { + if from.ConfigMapKeyRef != nil { + return fmt.Sprintf("configmap %s, key %s", from.ConfigMapKeyRef.Name, from.ConfigMapKeyRef.Key) + } + + if from.SecretKeyRef != nil { + return fmt.Sprintf("secret %s, key %s", from.SecretKeyRef.Name, from.SecretKeyRef.Key) + } + + if from.FieldRef != nil { + return fmt.Sprintf("field path %s", from.FieldRef.FieldPath) + } + + if from.ResourceFieldRef != nil { + containerPrefix := "" + if from.ResourceFieldRef.ContainerName != "" { + containerPrefix = fmt.Sprintf("%s/", from.ResourceFieldRef.ContainerName) + } + return fmt.Sprintf("resource field %s%s", containerPrefix, from.ResourceFieldRef.Resource) + } + + return "invalid valueFrom" +} + +// IsHugePageResourceName returns true if the resource name has the huge page +// resource prefix. +func IsHugePageResourceName(name corev1.ResourceName) bool { + return strings.HasPrefix(string(name), corev1.ResourceHugePagesPrefix) +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 3e7f0d6f43..1e564ed858 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -951,6 +951,9 @@ k8s.io/klog k8s.io/klog/v2 # k8s.io/kube-openapi v0.0.0-20210305001622-591a79e4bda7 k8s.io/kube-openapi/pkg/util/proto +# k8s.io/kubectl v0.20.2 +## explicit +k8s.io/kubectl/pkg/cmd/set/env # k8s.io/utils v0.0.0-20210111153108-fddb29f9d009 ## explicit k8s.io/utils/buffer