mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Moving v1beta1 kubectl examples to v1beta3
This commit is contained in:
parent
ffffbb7edf
commit
fe60be3179
@ -165,7 +165,7 @@ function wait-cluster-readiness {
|
|||||||
|
|
||||||
local timeout=50
|
local timeout=50
|
||||||
while [[ $timeout -ne 0 ]]; do
|
while [[ $timeout -ne 0 ]]; do
|
||||||
nb_ready_minions=$("${kubectl}" get minions -o template -t "{{range.items}}{{range.status.conditions}}{{.kind}}{{end}}:{{end}}" --api-version=v1beta1 2>/dev/null | tr ':' '\n' | grep -c Ready || true)
|
nb_ready_minions=$("${kubectl}" get nodes -o template -t "{{range.items}}{{range.status.conditions}}{{.kind}}{{end}}:{{end}}" --api-version=v1beta3 2>/dev/null | tr ':' '\n' | grep -c Ready || true)
|
||||||
echo "Nb ready minions: $nb_ready_minions / $NUM_MINIONS"
|
echo "Nb ready minions: $nb_ready_minions / $NUM_MINIONS"
|
||||||
if [[ "$nb_ready_minions" -eq "$NUM_MINIONS" ]]; then
|
if [[ "$nb_ready_minions" -eq "$NUM_MINIONS" ]]; then
|
||||||
return 0
|
return 0
|
||||||
|
@ -165,7 +165,7 @@ function verify-cluster {
|
|||||||
local count="0"
|
local count="0"
|
||||||
until [[ "$count" == "1" ]]; do
|
until [[ "$count" == "1" ]]; do
|
||||||
local minions
|
local minions
|
||||||
minions=$("${KUBE_ROOT}/cluster/kubectl.sh" get minions -o template -t '{{range.items}}{{.id}}:{{end}}' --api-version=v1beta1)
|
minions=$("${KUBE_ROOT}/cluster/kubectl.sh" get nodes -o template -t '{{range.items}}{{.metadata.name}}:{{end}}' --api-version=v1beta3)
|
||||||
count=$(echo $minions | grep -c "${MINION_IPS[i]}") || {
|
count=$(echo $minions | grep -c "${MINION_IPS[i]}") || {
|
||||||
printf "."
|
printf "."
|
||||||
sleep 2
|
sleep 2
|
||||||
|
@ -29,8 +29,8 @@ $ kubectl get replicationController web
|
|||||||
// List a single pod in JSON output format.
|
// List a single pod in JSON output format.
|
||||||
$ kubectl get -o json pod web-pod-13je7
|
$ kubectl get -o json pod web-pod-13je7
|
||||||
|
|
||||||
// Return only the status value of the specified pod.
|
// Return only the phase value of the specified pod.
|
||||||
$ kubectl get -o template web-pod-13je7 --template={{.currentState.status}} --api-version=v1beta1
|
$ kubectl get -o template web-pod-13je7 --template={{.status.phase}} --api-version=v1beta3
|
||||||
|
|
||||||
// List all replication controllers and services together in ps output format.
|
// List all replication controllers and services together in ps output format.
|
||||||
$ kubectl get rc,services
|
$ kubectl get rc,services
|
||||||
|
@ -175,8 +175,8 @@ $ kubectl get replicationController web
|
|||||||
// List a single pod in JSON output format.
|
// List a single pod in JSON output format.
|
||||||
$ kubectl get \-o json pod web\-pod\-13je7
|
$ kubectl get \-o json pod web\-pod\-13je7
|
||||||
|
|
||||||
// Return only the status value of the specified pod.
|
// Return only the phase value of the specified pod.
|
||||||
$ kubectl get \-o template web\-pod\-13je7 \-\-template=\{\{.currentState.status\}\} \-\-api\-version=v1beta1
|
$ kubectl get \-o template web\-pod\-13je7 \-\-template=\{\{.status.phase\}\} \-\-api\-version=v1beta3
|
||||||
|
|
||||||
// List all replication controllers and services together in ps output format.
|
// List all replication controllers and services together in ps output format.
|
||||||
$ kubectl get rc,services
|
$ kubectl get rc,services
|
||||||
|
@ -58,7 +58,7 @@ until [[ ${all_running} == 1 ]]; do
|
|||||||
echo "All pods never 'Running' in time." >&2
|
echo "All pods never 'Running' in time." >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
statuses=($(${KUBECTL} get pods --template='{{range.items}}{{.currentState.status}} {{end}}' --api-version=v1beta1))
|
statuses=($(${KUBECTL} get pods --template='{{range.items}}{{.status.phase}} {{end}}' --api-version=v1beta3))
|
||||||
|
|
||||||
# Ensure that we have enough pods.
|
# Ensure that we have enough pods.
|
||||||
echo "Found ${#statuses[@]} pods with statuses: ${statuses[@]}" >&2
|
echo "Found ${#statuses[@]} pods with statuses: ${statuses[@]}" >&2
|
||||||
|
@ -151,8 +151,8 @@ function query_pods() {
|
|||||||
local i
|
local i
|
||||||
for i in $(seq 1 10); do
|
for i in $(seq 1 10); do
|
||||||
pods_unsorted=($(${KUBECTL} get pods -o template \
|
pods_unsorted=($(${KUBECTL} get pods -o template \
|
||||||
'--template={{range.items}}{{.id}} {{end}}' \
|
'--template={{range.items}}{{.metadata.name}} {{end}}' \
|
||||||
'--api-version=v1beta1' \
|
'--api-version=v1beta3' \
|
||||||
-l name="$1"))
|
-l name="$1"))
|
||||||
found="${#pods_unsorted[*]}"
|
found="${#pods_unsorted[*]}"
|
||||||
if [[ "${found}" == "$2" ]]; then
|
if [[ "${found}" == "$2" ]]; then
|
||||||
@ -186,7 +186,7 @@ function wait_for_pods() {
|
|||||||
echo "Waiting for ${pods_needed} pods to become 'running'"
|
echo "Waiting for ${pods_needed} pods to become 'running'"
|
||||||
pods_needed="$2"
|
pods_needed="$2"
|
||||||
for id in ${pods_sorted}; do
|
for id in ${pods_sorted}; do
|
||||||
status=$(${KUBECTL} get pods "${id}" -o template --template='{{.currentState.status}}' --api-version=v1beta1)
|
status=$(${KUBECTL} get pods "${id}" -o template --template='{{.status.phase}}' --api-version=v1beta3)
|
||||||
if [[ "${status}" == "Running" ]]; then
|
if [[ "${status}" == "Running" ]]; then
|
||||||
pods_needed=$((pods_needed-1))
|
pods_needed=$((pods_needed-1))
|
||||||
fi
|
fi
|
||||||
@ -312,9 +312,9 @@ svc1_pods=$(query_pods "${svc1_name}" "${svc1_count}")
|
|||||||
svc2_pods=$(query_pods "${svc2_name}" "${svc2_count}")
|
svc2_pods=$(query_pods "${svc2_name}" "${svc2_count}")
|
||||||
|
|
||||||
# Get the portal IPs.
|
# Get the portal IPs.
|
||||||
svc1_ip=$(${KUBECTL} get services -o template '--template={{.portalIP}}' "${svc1_name}" --api-version=v1beta1)
|
svc1_ip=$(${KUBECTL} get services -o template '--template={{.spec.portalIP}}' "${svc1_name}" --api-version=v1beta3)
|
||||||
test -n "${svc1_ip}" || error "Service1 IP is blank"
|
test -n "${svc1_ip}" || error "Service1 IP is blank"
|
||||||
svc2_ip=$(${KUBECTL} get services -o template '--template={{.portalIP}}' "${svc2_name}" --api-version=v1beta1)
|
svc2_ip=$(${KUBECTL} get services -o template '--template={{.spec.portalIP}}' "${svc2_name}" --api-version=v1beta3)
|
||||||
test -n "${svc2_ip}" || error "Service2 IP is blank"
|
test -n "${svc2_ip}" || error "Service2 IP is blank"
|
||||||
if [[ "${svc1_ip}" == "${svc2_ip}" ]]; then
|
if [[ "${svc1_ip}" == "${svc2_ip}" ]]; then
|
||||||
error "Portal IPs conflict: ${svc1_ip}"
|
error "Portal IPs conflict: ${svc1_ip}"
|
||||||
@ -384,7 +384,7 @@ wait_for_pods "${svc3_name}" "${svc3_count}"
|
|||||||
svc3_pods=$(query_pods "${svc3_name}" "${svc3_count}")
|
svc3_pods=$(query_pods "${svc3_name}" "${svc3_count}")
|
||||||
|
|
||||||
# Get the portal IP.
|
# Get the portal IP.
|
||||||
svc3_ip=$(${KUBECTL} get services -o template '--template={{.portalIP}}' "${svc3_name}" --api-version=v1beta1)
|
svc3_ip=$(${KUBECTL} get services -o template '--template={{.spec.portalIP}}' "${svc3_name}" --api-version=v1beta3)
|
||||||
test -n "${svc3_ip}" || error "Service3 IP is blank"
|
test -n "${svc3_ip}" || error "Service3 IP is blank"
|
||||||
|
|
||||||
echo "Verifying the portals from the host"
|
echo "Verifying the portals from the host"
|
||||||
@ -440,7 +440,7 @@ wait_for_pods "${svc4_name}" "${svc4_count}"
|
|||||||
svc4_pods=$(query_pods "${svc4_name}" "${svc4_count}")
|
svc4_pods=$(query_pods "${svc4_name}" "${svc4_count}")
|
||||||
|
|
||||||
# Get the portal IP.
|
# Get the portal IP.
|
||||||
svc4_ip=$(${KUBECTL} get services -o template '--template={{.portalIP}}' "${svc4_name}" --api-version=v1beta1)
|
svc4_ip=$(${KUBECTL} get services -o template '--template={{.spec.portalIP}}' "${svc4_name}" --api-version=v1beta3)
|
||||||
test -n "${svc4_ip}" || error "Service4 IP is blank"
|
test -n "${svc4_ip}" || error "Service4 IP is blank"
|
||||||
if [[ "${svc4_ip}" == "${svc2_ip}" || "${svc4_ip}" == "${svc3_ip}" ]]; then
|
if [[ "${svc4_ip}" == "${svc2_ip}" || "${svc4_ip}" == "${svc3_ip}" ]]; then
|
||||||
error "Portal IPs conflict: ${svc4_ip}"
|
error "Portal IPs conflict: ${svc4_ip}"
|
||||||
|
@ -47,8 +47,8 @@ $ kubectl get replicationController web
|
|||||||
// List a single pod in JSON output format.
|
// List a single pod in JSON output format.
|
||||||
$ kubectl get -o json pod web-pod-13je7
|
$ kubectl get -o json pod web-pod-13je7
|
||||||
|
|
||||||
// Return only the status value of the specified pod.
|
// Return only the phase value of the specified pod.
|
||||||
$ kubectl get -o template web-pod-13je7 --template={{.currentState.status}} --api-version=v1beta1
|
$ kubectl get -o template web-pod-13je7 --template={{.status.phase}} --api-version=v1beta3
|
||||||
|
|
||||||
// List all replication controllers and services together in ps output format.
|
// List all replication controllers and services together in ps output format.
|
||||||
$ kubectl get rc,services
|
$ kubectl get rc,services
|
||||||
|
@ -367,7 +367,7 @@ func TestTemplateStrings(t *testing.T) {
|
|||||||
},
|
},
|
||||||
"false",
|
"false",
|
||||||
},
|
},
|
||||||
"oneValid": {
|
"barValid": {
|
||||||
api.Pod{
|
api.Pod{
|
||||||
Status: api.PodStatus{
|
Status: api.PodStatus{
|
||||||
ContainerStatuses: []api.ContainerStatus{
|
ContainerStatuses: []api.ContainerStatus{
|
||||||
@ -413,11 +413,11 @@ func TestTemplateStrings(t *testing.T) {
|
|||||||
"true",
|
"true",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// The point of this test is to verify that the below template works. If you change this
|
// The point of this test is to verify that the below template works. If you change this
|
||||||
// template, you need to update hack/e2e-suite/update.sh.
|
// template, you need to update hack/e2e-suite/update.sh.
|
||||||
tmpl :=
|
tmpl := ``
|
||||||
`{{and (exists . "currentState" "info" "foo" "state" "running") (exists . "currentState" "info" "bar" "state" "running")}}`
|
if api.PreV1Beta3(testapi.Version()) {
|
||||||
|
tmpl = `{{exists . "currentState" "info" "foo" "state" "running"}}`
|
||||||
useThisToDebug := `
|
useThisToDebug := `
|
||||||
a: {{exists . "currentState"}}
|
a: {{exists . "currentState"}}
|
||||||
b: {{exists . "currentState" "info"}}
|
b: {{exists . "currentState" "info"}}
|
||||||
@ -426,13 +426,15 @@ d: {{exists . "currentState" "info" "foo" "state"}}
|
|||||||
e: {{exists . "currentState" "info" "foo" "state" "running"}}
|
e: {{exists . "currentState" "info" "foo" "state" "running"}}
|
||||||
f: {{exists . "currentState" "info" "foo" "state" "running" "startedAt"}}`
|
f: {{exists . "currentState" "info" "foo" "state" "running" "startedAt"}}`
|
||||||
_ = useThisToDebug // don't complain about unused var
|
_ = useThisToDebug // don't complain about unused var
|
||||||
|
} else {
|
||||||
|
tmpl = `{{if (exists . "status" "containerStatuses")}}{{range .status.containerStatuses}}{{if (and (eq .name "foo") (exists . "state" "running"))}}true{{end}}{{end}}{{end}}`
|
||||||
|
}
|
||||||
p, err := NewTemplatePrinter([]byte(tmpl))
|
p, err := NewTemplatePrinter([]byte(tmpl))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("tmpl fail: %v", err)
|
t.Fatalf("tmpl fail: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
printer := NewVersionedPrinter(p, api.Scheme, "v1beta1")
|
printer := NewVersionedPrinter(p, api.Scheme, testapi.Version())
|
||||||
|
|
||||||
for name, item := range table {
|
for name, item := range table {
|
||||||
buffer := &bytes.Buffer{}
|
buffer := &bytes.Buffer{}
|
||||||
@ -441,8 +443,12 @@ f: {{exists . "currentState" "info" "foo" "state" "running" "startedAt"}}`
|
|||||||
t.Errorf("%v: unexpected err: %v", name, err)
|
t.Errorf("%v: unexpected err: %v", name, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if e, a := item.expect, buffer.String(); e != a {
|
actual := buffer.String()
|
||||||
t.Errorf("%v: expected %v, got %v", name, e, a)
|
if len(actual) == 0 {
|
||||||
|
actual = "false"
|
||||||
|
}
|
||||||
|
if e := item.expect; e != actual {
|
||||||
|
t.Errorf("%v: expected %v, got %v", name, e, actual)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -216,7 +216,7 @@ type validatorFn func(c *client.Client, podID string) error
|
|||||||
// "testname": which gets bubbled up to the logging/failure messages if errors happen.
|
// "testname": which gets bubbled up to the logging/failure messages if errors happen.
|
||||||
// "validator" function: This function is given a podID and a client, and it can do some specific validations that way.
|
// "validator" function: This function is given a podID and a client, and it can do some specific validations that way.
|
||||||
func validateController(c *client.Client, containerImage string, replicas int, containername string, testname string, validator validatorFn) {
|
func validateController(c *client.Client, containerImage string, replicas int, containername string, testname string, validator validatorFn) {
|
||||||
getPodsTemplate := "--template={{range.items}}{{.id}} {{end}}"
|
getPodsTemplate := "--template={{range.items}}{{.metadata.name}} {{end}}"
|
||||||
// NB: kubectl adds the "exists" function to the standard template functions.
|
// NB: kubectl adds the "exists" function to the standard template functions.
|
||||||
// This lets us check to see if the "running" entry exists for each of the containers
|
// This lets us check to see if the "running" entry exists for each of the containers
|
||||||
// we care about. Exists will never return an error and it's safe to check a chain of
|
// we care about. Exists will never return an error and it's safe to check a chain of
|
||||||
@ -225,13 +225,13 @@ func validateController(c *client.Client, containerImage string, replicas int, c
|
|||||||
// helpful.
|
// helpful.
|
||||||
// This template is unit-tested in kubectl, so if you change it, update the unit test.
|
// This template is unit-tested in kubectl, so if you change it, update the unit test.
|
||||||
// You can read about the syntax here: http://golang.org/pkg/text/template/.
|
// You can read about the syntax here: http://golang.org/pkg/text/template/.
|
||||||
getContainerStateTemplate := fmt.Sprintf(`--template={{and (exists . "currentState" "info" "%s" "state" "running")}}`, containername)
|
getContainerStateTemplate := fmt.Sprintf(`--template={{if (exists . "status" "containerStatuses")}}{{range .status.containerStatuses}}{{if (and (eq .name "%s") (exists . "state" "running"))}}true{{end}}{{end}}{{end}}`, containername)
|
||||||
|
|
||||||
getImageTemplate := fmt.Sprintf(`--template={{(index .currentState.info "%s").image}}`, containername)
|
getImageTemplate := fmt.Sprintf(`--template={{if (exists . "status" "containerStatuses")}}{{range .status.containerStatuses}}{{if eq .name "%s"}}{{.image}}{{end}}{{end}}{{end}}`, containername)
|
||||||
|
|
||||||
By(fmt.Sprintf("waiting for all containers in %s pods to come up.", testname)) //testname should be selector
|
By(fmt.Sprintf("waiting for all containers in %s pods to come up.", testname)) //testname should be selector
|
||||||
for start := time.Now(); time.Since(start) < podStartTimeout; time.Sleep(5 * time.Second) {
|
for start := time.Now(); time.Since(start) < podStartTimeout; time.Sleep(5 * time.Second) {
|
||||||
getPodsOutput := runKubectl("get", "pods", "-o", "template", getPodsTemplate, "--api-version=v1beta1", "-l", testname)
|
getPodsOutput := runKubectl("get", "pods", "-o", "template", getPodsTemplate, "--api-version=v1beta3", "-l", testname)
|
||||||
pods := strings.Fields(getPodsOutput)
|
pods := strings.Fields(getPodsOutput)
|
||||||
if numPods := len(pods); numPods != replicas {
|
if numPods := len(pods); numPods != replicas {
|
||||||
By(fmt.Sprintf("Replicas for %s: expected=%d actual=%d", testname, replicas, numPods))
|
By(fmt.Sprintf("Replicas for %s: expected=%d actual=%d", testname, replicas, numPods))
|
||||||
@ -239,13 +239,13 @@ func validateController(c *client.Client, containerImage string, replicas int, c
|
|||||||
}
|
}
|
||||||
var runningPods []string
|
var runningPods []string
|
||||||
for _, podID := range pods {
|
for _, podID := range pods {
|
||||||
running := runKubectl("get", "pods", podID, "-o", "template", getContainerStateTemplate, "--api-version=v1beta1")
|
running := runKubectl("get", "pods", podID, "-o", "template", getContainerStateTemplate, "--api-version=v1beta3")
|
||||||
if running == "false" {
|
if running != "true" {
|
||||||
Logf("%s is created but not running", podID)
|
Logf("%s is created but not running", podID)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
currentImage := runKubectl("get", "pods", podID, "-o", "template", getImageTemplate, "--api-version=v1beta1")
|
currentImage := runKubectl("get", "pods", podID, "-o", "template", getImageTemplate, "--api-version=v1beta3")
|
||||||
if currentImage != containerImage {
|
if currentImage != containerImage {
|
||||||
Logf("%s is created but running wrong image; expected: %s, actual: %s", podID, containerImage, currentImage)
|
Logf("%s is created but running wrong image; expected: %s, actual: %s", podID, containerImage, currentImage)
|
||||||
continue
|
continue
|
||||||
|
Loading…
Reference in New Issue
Block a user