Skip to content

Commit 4853374

Browse files
committed
Add functional test
Signed-off-by: Dominique Vernier <[email protected]>
1 parent 1156193 commit 4853374

File tree

5 files changed

+44
-17
lines changed

5 files changed

+44
-17
lines changed

CHANGELOG.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
[comment]: # ( Copyright Contributors to the Open Cluster Management project )
22
# Release Content
3+
## Additions
4+
- Add `clusteradm delete token` [Create cmd to revoke the bootstrap token](https://github.com/open-cluster-management-io/clusteradm/issues/23)
35

4-
- Add support for non-bootstrap token enabled environment [issue 16](https://github.com/open-cluster-management-io/clusteradm/issues/16)
5-
- Avoid to run the `clusteradm init` twice on the hub [issue 21](https://github.com/open-cluster-management-io/clusteradm/issues/21)
6-
- Add command `clusteradm get token` [issue 22](https://github.com/open-cluster-management-io/clusteradm/issues/22)
6+
## Breaking Changes
7+
8+
## Changes
9+
10+
## Bug Fixes

VERSION.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.0-alpha.3
1+
0.1.0-alpha.4

build/run-functional-tests.sh

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function joinscenario() {
6969
CMDJOINRESULT=$(join_hub "${CMDINITRESULT}" $1)
7070
echo "join command result: "$CMDJOINRESULT >&2
7171

72-
echo "Wait 4 min to stabilize" >&2
72+
echo "Wait 4 min maximum to stabilize" >&2
7373

7474
kubectl config use-context kind-${CLUSTER_NAME}-hub
7575
CMDACCEPTRESULT=$(accept_cluster "${CMDJOINRESULT}")
@@ -85,17 +85,18 @@ function joinscenario() {
8585

8686
function gettokenscenario() {
8787
echo "gettokenscenario 1st parameter: "$1 >&2
88+
echo "gettokenscenario 2nd parameter: "$2 >&2
8889
echo "get token from hub" >&2
8990
kubectl config use-context kind-${CLUSTER_NAME}-hub
90-
CMGETTOKENRESULT=$(gettoken)
91+
CMGETTOKENRESULT=$(gettoken $2)
9192
echo "get token command result: "$CMGETTOKENRESULT >&2
9293

9394
echo "join hub" >&2
9495
kubectl config use-context kind-${CLUSTER_NAME}-$1
9596
CMDJOINRESULT=$(join_hub "${CMGETTOKENRESULT}" $1)
9697
echo "join command result: "$CMDJOINRESULT >&1
9798

98-
echo "Wait 4 min to stabilize" >&2
99+
echo "Wait 4 min maximum to stabilize" >&2
99100

100101
kubectl config use-context kind-${CLUSTER_NAME}-hub
101102
CMDACCEPTRESULT=$(accept_cluster "${CMDJOINRESULT}")
@@ -107,6 +108,22 @@ function gettokenscenario() {
107108
else
108109
echo "accept command result: "$CMDACCEPTRESULT >&2
109110
fi
111+
112+
echo "delete token" >&2
113+
clusteradm delete token
114+
if [ $? != 0 ]
115+
then
116+
echo "accept command result: "$CMDACCEPTRESULT >&2
117+
ERROR_REPORT=$ERROR_REPORT+"no CSR get approved\n"
118+
fi
119+
120+
echo "get token from hub" >&2
121+
kubectl config use-context kind-${CLUSTER_NAME}-hub
122+
CMGETTOKENRESULT2=$(gettoken $2)
123+
if [ "$CMGETTOKENRESULT" == "$CMGETTOKENRESULT2" ]
124+
then
125+
ERROR_REPORT=$ERROR_REPORT+"new token identical as previous token after delete"
126+
fi
110127
}
111128

112129
echo "With bootstrap token"
@@ -132,7 +149,7 @@ kind delete cluster --name ${CLUSTER_NAME}-c1
132149
kind create cluster --name ${CLUSTER_NAME}-c2
133150
echo "Joining with get token and bootstrap token"
134151
echo "------------------------------------------"
135-
gettokenscenario c2
152+
gettokenscenario c2 --use-bootstrap-token
136153

137154
kind delete cluster --name ${CLUSTER_NAME}-hub
138155
kind delete cluster --name ${CLUSTER_NAME}-c2

pkg/cmd/delete/token/exec.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,12 @@ func (o *Options) deleteToken(kubeClient *kubernetes.Clientset) error {
7474

7575
//Detele bootstrap token secret
7676
secret, err := helpers.GetBootstrapSecret(kubeClient)
77-
if err != nil && !errors.IsNotFound(err) {
78-
return err
77+
if err == nil {
78+
err = kubeClient.CoreV1().Secrets(secret.Namespace).Delete(context.TODO(), secret.Name, metav1.DeleteOptions{})
79+
if err != nil && !errors.IsNotFound(err) {
80+
return err
81+
}
7982
}
80-
err = kubeClient.CoreV1().Secrets(secret.Namespace).Delete(context.TODO(), secret.Name, metav1.DeleteOptions{})
8183
if err != nil && !errors.IsNotFound(err) {
8284
return err
8385
}

pkg/helpers/client.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,12 @@ func GetBootstrapSecretFromSA(
157157
return nil, err
158158
}
159159
var secret *corev1.Secret
160+
var prefix string
160161
for _, objectRef := range sa.Secrets {
161162
if objectRef.Namespace != "" && objectRef.Namespace != config.OpenClusterManagementNamespace {
162163
continue
163164
}
164-
prefix := config.BootstrapSAName
165+
prefix = config.BootstrapSAName
165166
if len(prefix) > 63 {
166167
prefix = prefix[:37]
167168
}
@@ -178,11 +179,14 @@ func GetBootstrapSecretFromSA(
178179
}
179180
}
180181
if secret == nil {
181-
return nil, fmt.Errorf("secret with prefix %s and type %s not found in service account %s/%s",
182-
config.BootstrapSAName,
183-
corev1.SecretTypeServiceAccountToken,
184-
config.OpenClusterManagementNamespace,
185-
config.BootstrapSAName)
182+
return nil, errors.NewNotFound(schema.GroupResource{
183+
Group: corev1.GroupName,
184+
Resource: "secrets"},
185+
fmt.Sprintf("secret with prefix %s and type %s not found in service account %s/%s",
186+
prefix,
187+
corev1.SecretTypeServiceAccountToken,
188+
config.OpenClusterManagementNamespace,
189+
config.BootstrapSAName))
186190
}
187191
return secret, nil
188192
}

0 commit comments

Comments
 (0)