...

Text file src/k8s.io/kubernetes/test/cmd/convert.sh

Documentation: k8s.io/kubernetes/test/cmd

     1#!/usr/bin/env bash
     2
     3# Copyright 2021 The Kubernetes Authors.
     4#
     5# Licensed under the Apache License, Version 2.0 (the "License");
     6# you may not use this file except in compliance with the License.
     7# You may obtain a copy of the License at
     8#
     9#     http://www.apache.org/licenses/LICENSE-2.0
    10#
    11# Unless required by applicable law or agreed to in writing, software
    12# distributed under the License is distributed on an "AS IS" BASIS,
    13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14# See the License for the specific language governing permissions and
    15# limitations under the License.
    16
    17set -o errexit
    18set -o nounset
    19set -o pipefail
    20
    21run_convert_tests() {
    22  set -o nounset
    23  set -o errexit
    24
    25  ### Convert deployment YAML file locally without affecting the live deployment
    26  # Pre-condition: no deployments exist
    27  kube::test::get_object_assert deployment "{{range.items}}{{${id_field:?}}}:{{end}}" ''
    28  # Command
    29  # Create a deployment (revision 1)
    30  kubectl create -f hack/testdata/deployment-revision1.yaml "${kube_flags[@]:?}"
    31  kube::test::get_object_assert deployment "{{range.items}}{{${id_field:?}}}:{{end}}" 'nginx:'
    32  kube::test::get_object_assert deployment "{{range.items}}{{${image_field0:?}}}:{{end}}" "${IMAGE_DEPLOYMENT_R1}:"
    33  # Command
    34  output_message=$(kubectl convert --local -f hack/testdata/deployment-revision1.yaml --output-version=apps/v1beta1 -o yaml "${kube_flags[@]:?}")
    35  # Post-condition: apiVersion is still apps/v1 in the live deployment, but command output is the new value
    36  kube::test::get_object_assert 'deployment nginx' "{{ .apiVersion }}" 'apps/v1'
    37  kube::test::if_has_string "${output_message}" "apps/v1beta1"
    38  # Clean up
    39  kubectl delete deployment nginx "${kube_flags[@]:?}"
    40
    41  ## Convert multiple busybox PODs recursively from directory of YAML files
    42  # Command
    43  output_message=$(! kubectl-convert -f hack/testdata/recursive/pod --recursive 2>&1 "${kube_flags[@]:?}")
    44  # Post-condition: busybox0 & busybox1 PODs are converted, and since busybox2 is malformed, it should error
    45  kube::test::if_has_string "${output_message}" "Object 'Kind' is missing"
    46
    47  # check that convert command supports --template output
    48  output_message=$(kubectl-convert "${kube_flags[@]:?}" -f hack/testdata/deployment-revision1.yaml --output-version=apps/v1beta2 --template="{{ .metadata.name }}:")
    49  kube::test::if_has_string "${output_message}" 'nginx:'
    50
    51  set +o nounset
    52  set +o errexit
    53}

View as plain text