Skip to content

Commit

Permalink
Add make cluster/kubeconfig
Browse files Browse the repository at this point in the history
Signed-off-by: Connor Catlett <[email protected]>
  • Loading branch information
ConnorJC3 committed Apr 30, 2024
1 parent 82d0804 commit 6898093
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ all-push: all-image-registry push-manifest
cluster/create: bin/kops bin/eksctl bin/aws
./hack/e2e/create-cluster.sh

.PHONY: cluster/kubeconfig
cluster/kubeconfig:
@./hack/e2e/kubeconfig.sh

.PHONY: cluster/delete
cluster/delete: bin/kops bin/eksctl
./hack/e2e/delete-cluster.sh
Expand Down
17 changes: 17 additions & 0 deletions docs/makefile.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,23 @@ export CLUSTER_TYPE="eksctl"
make cluster/create
```

### `make cluster/kubeconfig`

Prints the `KUBECONFIG` environment variable for a cluster. You must pass the same `CLUSTER_TYPE` and `CLUSTER_NAME` as used when creating the cluster. This command must be `eval`ed to import the environment variables into your shell.

#### Example: Export the `KUBECONFIG` for a default cluster

```bash
eval "$(make cluster/kubeconfig)"
```

#### Example: Export the `KUBECONFIG` for an `eksctl` cluster

```bash
export CLUSTER_TYPE="eksctl"
eval "$(make cluster/kubeconfig)"
```

### `make cluster/delete`

Deletes a cluster created by `make cluster/create`. You must pass the same `CLUSTER_TYPE` and `CLUSTER_NAME` as used when creating the cluster.
Expand Down
27 changes: 27 additions & 0 deletions hack/e2e/kubeconfig.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

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

# This script echos the KUBECONFIG back to the caller
# CLUSTER_NAME and CLUSTER_TYPE are expected to be specified by the caller

set -euo pipefail

BASE_DIR="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"
KUBECONFIG="${BASE_DIR}/csi-test-artifacts/${CLUSTER_NAME}.${CLUSTER_TYPE}.kubeconfig"

echo "# Makefiles cannot export environment variables directly"
echo "# Run eval \"\$(make cluster/kubeconfig)\""
echo "export KUBECONFIG=\"${KUBECONFIG}\""

0 comments on commit 6898093

Please sign in to comment.