Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add kubectl-convert to client-binaries #99155

Merged
merged 2 commits into from Feb 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions build/BUILD
Expand Up @@ -124,6 +124,7 @@ release_filegroup(
name = "client-targets",
conditioned_srcs = for_platforms(for_client = [
"//cmd/kubectl",
"//cmd/kubectl-convert",
]),
)

Expand Down
2 changes: 1 addition & 1 deletion cmd/kubectl-convert/BUILD
Expand Up @@ -6,7 +6,7 @@ load(
load("//staging/src/k8s.io/component-base/version:def.bzl", "version_x_defs")

go_binary(
name = "kubectl",
name = "kubectl-convert",
embed = [":go_default_library"],
pure = "on",
visibility = ["//visibility:public"],
Expand Down
1 change: 1 addition & 0 deletions hack/lib/golang.sh
Expand Up @@ -248,6 +248,7 @@ kube::golang::setup_platforms
# If you update this list, please also update build/BUILD.
readonly KUBE_CLIENT_TARGETS=(
cmd/kubectl
cmd/kubectl-convert
)
readonly KUBE_CLIENT_BINARIES=("${KUBE_CLIENT_TARGETS[@]##*/}")
readonly KUBE_CLIENT_BINARIES_WIN=("${KUBE_CLIENT_BINARIES[@]/%/.exe}")
Expand Down
53 changes: 53 additions & 0 deletions test/cmd/convert.sh
@@ -0,0 +1,53 @@
#!/usr/bin/env bash

# Copyright 2021 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.

set -o errexit
set -o nounset
set -o pipefail

run_convert_tests() {
set -o nounset
set -o errexit

### Convert deployment YAML file locally without affecting the live deployment
# Pre-condition: no deployments exist
kube::test::get_object_assert deployment "{{range.items}}{{${id_field:?}}}:{{end}}" ''
# Command
# Create a deployment (revision 1)
kubectl create -f hack/testdata/deployment-revision1.yaml "${kube_flags[@]:?}"
kube::test::get_object_assert deployment "{{range.items}}{{${id_field:?}}}:{{end}}" 'nginx:'
kube::test::get_object_assert deployment "{{range.items}}{{${image_field0:?}}}:{{end}}" "${IMAGE_DEPLOYMENT_R1}:"
# Command
output_message=$(kubectl convert --local -f hack/testdata/deployment-revision1.yaml --output-version=apps/v1beta1 -o yaml "${kube_flags[@]:?}")
# Post-condition: apiVersion is still apps/v1 in the live deployment, but command output is the new value
kube::test::get_object_assert 'deployment nginx' "{{ .apiVersion }}" 'apps/v1'
kube::test::if_has_string "${output_message}" "apps/v1beta1"
# Clean up
kubectl delete deployment nginx "${kube_flags[@]:?}"

## Convert multiple busybox PODs recursively from directory of YAML files
# Command
output_message=$(! kubectl-convert -f hack/testdata/recursive/pod --recursive 2>&1 "${kube_flags[@]:?}")
# Post-condition: busybox0 & busybox1 PODs are converted, and since busybox2 is malformed, it should error
kube::test::if_has_string "${output_message}" "Object 'Kind' is missing"

# check that convert command supports --template output
output_message=$(kubectl-convert "${kube_flags[@]:?}" -f hack/testdata/deployment-revision1.yaml --output-version=apps/v1beta2 --template="{{ .metadata.name }}:")
kube::test::if_has_string "${output_message}" 'nginx:'

set +o nounset
set +o errexit
}
10 changes: 9 additions & 1 deletion test/cmd/legacy-script.sh
Expand Up @@ -33,6 +33,7 @@ source "${KUBE_ROOT}/test/cmd/authentication.sh"
source "${KUBE_ROOT}/test/cmd/authorization.sh"
source "${KUBE_ROOT}/test/cmd/batch.sh"
source "${KUBE_ROOT}/test/cmd/certificate.sh"
source "${KUBE_ROOT}/test/cmd/convert.sh"
source "${KUBE_ROOT}/test/cmd/core.sh"
source "${KUBE_ROOT}/test/cmd/crd.sh"
source "${KUBE_ROOT}/test/cmd/create.sh"
Expand Down Expand Up @@ -298,7 +299,7 @@ setup() {
kube::util::ensure-gnu-sed

kube::log::status "Building kubectl"
make -C "${KUBE_ROOT}" WHAT="cmd/kubectl"
make -C "${KUBE_ROOT}" WHAT="cmd/kubectl cmd/kubectl-convert"

# Check kubectl
kube::log::status "Running kubectl with no options"
Expand Down Expand Up @@ -561,6 +562,13 @@ runTests() {
record_command run_kubectl_create_kustomization_directory_tests
fi

######################
# Convert #
######################
if kube::test::if_supports_resource "${deployments}"; then
record_command run_convert_tests
fi

######################
# Delete #
######################
Expand Down