k8s.io/test-infra@v0.0.0-20240520184403-27c6b4c223d8/hack/Makefile.gcloud.mk (about) 1 # Copyright 2021 The Kubernetes Authors. 2 # 3 # Licensed under the Apache License, Version 2.0 (the "License"); 4 # you may not use this file except in compliance with the License. 5 # You may obtain a copy of the License at 6 # 7 # http://www.apache.org/licenses/LICENSE-2.0 8 # 9 # Unless required by applicable law or agreed to in writing, software 10 # distributed under the License is distributed on an "AS IS" BASIS, 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # See the License for the specific language governing permissions and 13 # limitations under the License. 14 15 # # README 16 # 17 # These rules are for setting up Kube current-context, so that later kubectl command 18 # knows which cluster to work on. 19 # It is highly recommended to import this rule for manipulating prow/build clusters, 20 # which helps prevent from targeting current-cluster context from your local environment. 21 22 # For working with prow service cluster: 23 # CLUSTER = "<CLUSTER_NAME>" # e.g. `prow` 24 # PROJECT = "<GCP_PROJECT_NAME_WHERE_CLUSTER_IS_IN>" # e.g. `k8s-prow` 25 # ZONE = "<GCP_ZONE_NAME_WHERE_CLUSTER_IS_IN>" # e.g. us-west1-b 26 # deploy-prow: get-cluster-credentials 27 # 28 # For working with prow build cluster: 29 # CLUSTER_BUILD = "<BUILD_CLUSTER_NAME>" # e.g. `prow-build` 30 # PROJECT_BUILD = "<GCP_PROJECT_NAME_WHERE_BUILD_CLUSTER_IS_IN>" # e.g. `k8s-prow-builds` 31 # ZONE_BUILD = "<GCP_ZONE_NAME_WHERE_BUILD_CLUSTER_IS_IN >" # e.g. us-west1-b 32 # deploy-prow: get-build-cluster-credentials 33 34 # These rules only take effect on rule explicitly importing them, it won't be applied on subsequent 35 # kubectl calls, nor changes your local Kube current-context. 36 37 export KUBECONFIG 38 39 # By default get-cluster-credentials saves Kube current-context after execution. 40 # Add this rule to prevents the Kube current-context in the execution environment from being 41 # overwritten unless the intention is made explicit w/ the `save` parameter. 42 # e.g. 43 # make get-cluster-credentials save=true 44 .PHONY: save-kubeconfig 45 save-kubeconfig: 46 ifndef save 47 $(eval KUBECONFIG=$(shell mktemp)) 48 endif 49 50 .PHONY: activate-serviceaccount 51 activate-serviceaccount: 52 ifdef GOOGLE_APPLICATION_CREDENTIALS 53 gcloud auth activate-service-account --key-file="$(GOOGLE_APPLICATION_CREDENTIALS)" 54 endif 55 56 .PHONY: get-cluster-credentials 57 get-cluster-credentials: save-kubeconfig activate-serviceaccount 58 gcloud container clusters get-credentials "$(CLUSTER)" --project="$(PROJECT)" --zone="$(ZONE)" 59 60 .PHONY: get-build-cluster-credentials 61 get-build-cluster-credentials: save-kubeconfig activate-serviceaccount 62 gcloud container clusters get-credentials "$(CLUSTER_BUILD)" --project="$(PROJECT_BUILD)" --zone="$(ZONE_BUILD)"