#!/bin/bash # Copyright 2016 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. # Script to fetch latest openapi spec. # Puts the updated spec at api/openapi-spec/ set -o errexit set -o nounset set -o pipefail global KUBE_ROOT := "$[dirname $(BASH_SOURCE)]/.." global OPENAPI_ROOT_DIR := ""$(KUBE_ROOT)/api/openapi-spec"" source "$(KUBE_ROOT)/hack/lib/init.sh" kube::golang::setup_env make -C $(KUBE_ROOT) WHAT=cmd/kube-apiserver proc cleanup { [[ -n ${APISERVER_PID-} ]] && kill $(APISERVER_PID) !1 > !2 !2 >/dev/null kube::etcd::cleanup kube::log::status "Clean up complete" } trap cleanup EXIT SIGINT kube::golang::setup_env global apiserver := $[kube::util::find-binary "kube-apiserver] global TMP_DIR := $[mktemp -d /tmp/update-openapi-spec.XXXX] global ETCD_HOST := $(ETCD_HOST:-127.0.0.1) global ETCD_PORT := $(ETCD_PORT:-2379) global API_PORT := $(API_PORT:-8050) global API_HOST := $(API_HOST:-127.0.0.1) kube::etcd::start echo "dummy_token,admin,admin" > $TMP_DIR/tokenauth.csv # Start kube-apiserver kube::log::status "Starting kube-apiserver" "$(KUBE_OUTPUT_HOSTBIN)/kube-apiserver" \ --insecure-bind-address="$(API_HOST)" \ --bind-address="$(API_HOST)" \ --insecure-port="$(API_PORT)" \ --etcd-servers="http://$(ETCD_HOST):$(ETCD_PORT)" \ --advertise-address="10.10.10.10" \ --cert-dir="$(TMP_DIR)/certs" \ --runtime-config="api/all=true" \ --token-auth-file=$TMP_DIR/tokenauth.csv \ --logtostderr \ --v=2 \ --service-cluster-ip-range="10.0.0.0/24" >/tmp/openapi-api-server.log !2 > !1 & global APISERVER_PID := $BgPid kube::util::wait_for_url "$(API_HOST):$(API_PORT)/healthz" "apiserver: " kube::log::status "Updating " $(OPENAPI_ROOT_DIR) curl -w "\n" -fs "$(API_HOST):$(API_PORT)/swagger.json" > "$(OPENAPI_ROOT_DIR)/swagger.json" kube::log::status "SUCCESS" # ex: ts=2 sw=2 et filetype=sh (CommandList children: [ (C {(set)} {(-o)} {(errexit)}) (C {(set)} {(-o)} {(nounset)}) (C {(set)} {(-o)} {(pipefail)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:KUBE_ROOT) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [(C {(dirname)} {(DQ (${ VSub_Name BASH_SOURCE))})] ) left_token: spids: [71 79] ) (/..) } spids: [70] ) ] spids: [70] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:OPENAPI_ROOT_DIR) op: Equal rhs: {(DQ (${ VSub_Name KUBE_ROOT) (/api/openapi-spec))} spids: [82] ) ] spids: [82] ) (C {(source)} {(DQ (${ VSub_Name KUBE_ROOT) (/hack/lib/init.sh))}) (C {(kube) (Lit_Other ":") (Lit_Other ":") (golang) (Lit_Other ":") (Lit_Other ":") (setup_env)}) (C {(make)} {(-C)} {(DQ (${ VSub_Name KUBE_ROOT))} {(Lit_VarLike "WHAT=") (cmd/kube-apiserver)}) (FuncDef name: cleanup body: (BraceGroup children: [ (AndOr children: [ (DBracket expr: (BoolUnary op_id: BoolUnary_n child: { (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_Hyphen arg_word:{}) spids: [136 139] ) } ) ) (SimpleCommand words: [{(kill)} {(${ VSub_Name APISERVER_PID)}] redirects: [ (Redir op_id:Redir_GreatAnd fd:1 arg_word:{(2)} spids:[151]) (Redir op_id: Redir_Great fd: 2 arg_word: {(/dev/null)} spids: [154] ) ] ) ] op_id: Op_DAmp ) (C {(kube) (Lit_Other ":") (Lit_Other ":") (etcd) (Lit_Other ":") (Lit_Other ":") (cleanup)} ) (C {(kube) (Lit_Other ":") (Lit_Other ":") (log) (Lit_Other ":") (Lit_Other ":") (status)} {(DQ ("Clean up complete"))} ) ] spids: [129] ) spids: [123 128] ) (C {(trap)} {(cleanup)} {(EXIT)} {(SIGINT)}) (C {(kube) (Lit_Other ":") (Lit_Other ":") (golang) (Lit_Other ":") (Lit_Other ":") (setup_env)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:apiserver) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (C {(kube) (Lit_Other ":") (Lit_Other ":") (util) (Lit_Other ":") (Lit_Other ":") (find-binary) } {(DQ (kube-apiserver))} ) ] ) left_token: spids: [203 215] ) } spids: [202] ) ] spids: [202] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:TMP_DIR) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [(C {(mktemp)} {(-d)} {(/tmp/update-openapi-spec.XXXX)})] ) left_token: spids: [219 225] ) } spids: [218] ) ] spids: [218] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:ETCD_HOST) op: Equal rhs: { (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{(127.0.0.1)}) spids: [228 232] ) } spids: [227] ) ] spids: [227] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:ETCD_PORT) op: Equal rhs: { (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{(2379)}) spids: [235 239] ) } spids: [234] ) ] spids: [234] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:API_PORT) op: Equal rhs: { (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{(8050)}) spids: [242 246] ) } spids: [241] ) ] spids: [241] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:API_HOST) op: Equal rhs: { (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{(127.0.0.1)}) spids: [249 253] ) } spids: [248] ) ] spids: [248] ) (C {(kube) (Lit_Other ":") (Lit_Other ":") (etcd) (Lit_Other ":") (Lit_Other ":") (start)}) (SimpleCommand words: [{(echo)} {(DQ ("dummy_token,admin,admin"))}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {($ VSub_Name "$TMP_DIR") (/tokenauth.csv)} spids: [271] ) ] ) (C {(kube) (Lit_Other ":") (Lit_Other ":") (log) (Lit_Other ":") (Lit_Other ":") (status)} {(DQ ("Starting kube-apiserver"))} ) (Sentence child: (SimpleCommand words: [ {(DQ (${ VSub_Name KUBE_OUTPUT_HOSTBIN) (/kube-apiserver))} {(--insecure-bind-address) (Lit_Other "=") (DQ (${ VSub_Name API_HOST))} {(--bind-address) (Lit_Other "=") (DQ (${ VSub_Name API_HOST))} {(--insecure-port) (Lit_Other "=") (DQ (${ VSub_Name API_PORT))} {(--etcd-servers) (Lit_Other "=") (DQ ("http://") (${ VSub_Name ETCD_HOST) (":") (${ VSub_Name ETCD_PORT)) } {(--advertise-address) (Lit_Other "=") (DQ (10.10.10.10))} {(--cert-dir) (Lit_Other "=") (DQ (${ VSub_Name TMP_DIR) (/certs))} {(--runtime-config) (Lit_Other "=") (DQ ("api/all=true"))} {(--token-auth-file) (Lit_Other "=") ($ VSub_Name "$TMP_DIR") (/tokenauth.csv)} {(--logtostderr)} {(--v) (Lit_Other "=") (2)} {(--service-cluster-ip-range) (Lit_Other "=") (DQ (10.0.0.0/24))} ] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/tmp/openapi-api-server.log)} spids: [396] ) (Redir op_id:Redir_GreatAnd fd:2 arg_word:{(1)} spids:[399]) ] ) terminator: ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:APISERVER_PID) op: Equal rhs: {($ VSub_Bang "$!")} spids: [404] ) ] spids: [404] ) (C {(kube) (Lit_Other ":") (Lit_Other ":") (util) (Lit_Other ":") (Lit_Other ":") (wait_for_url)} {(DQ (${ VSub_Name API_HOST) (":") (${ VSub_Name API_PORT) (/healthz))} {(DQ ("apiserver: "))} ) (C {(kube) (Lit_Other ":") (Lit_Other ":") (log) (Lit_Other ":") (Lit_Other ":") (status)} {(DQ ("Updating "))} {(${ VSub_Name OPENAPI_ROOT_DIR)} ) (SimpleCommand words: [ {(curl)} {(-w)} {(DQ (EscapedLiteralPart token:))} {(-fs)} {(DQ (${ VSub_Name API_HOST) (":") (${ VSub_Name API_PORT) (/swagger.json))} ] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(DQ (${ VSub_Name OPENAPI_ROOT_DIR) (/swagger.json))} spids: [470] ) ] ) (C {(kube) (Lit_Other ":") (Lit_Other ":") (log) (Lit_Other ":") (Lit_Other ":") (status)} {(DQ (SUCCESS))} ) ] )