This repository has been archived by the owner on Dec 21, 2023. It is now read-only.
generated from giantswarm/template-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.go
65 lines (54 loc) · 1.66 KB
/
common.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package tests
import (
"context"
"fmt"
"os"
"github.com/google/uuid"
"github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
capa "sigs.k8s.io/cluster-api-provider-aws/api/v1beta1"
capi "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/controller-runtime/pkg/client"
)
const (
TestDescription = "test resource for aws-network-topology-operator"
)
func GenerateGUID(prefix string) string {
guid := uuid.NewString()
return fmt.Sprintf("%s-%s", prefix, guid[:13])
}
func GetEnvOrSkip(env string) string {
value := os.Getenv(env)
if value == "" {
ginkgo.Skip(fmt.Sprintf("%s not exported", env))
}
return value
}
func PatchClusterStatus(k8sClient client.Client, cluster *capi.Cluster, status capi.ClusterStatus) {
patchedCluster := cluster.DeepCopy()
patchedCluster.Status = status
err := k8sClient.Status().Patch(context.Background(), patchedCluster, client.MergeFrom(cluster))
if k8serrors.IsNotFound(err) {
return
}
nsName := types.NamespacedName{
Name: cluster.Name,
Namespace: cluster.Namespace,
}
Expect(k8sClient.Get(context.Background(), nsName, cluster)).To(Succeed())
}
func PatchAWSClusterStatus(k8sClient client.Client, cluster *capa.AWSCluster, status capa.AWSClusterStatus) {
patchedCluster := cluster.DeepCopy()
patchedCluster.Status = status
err := k8sClient.Status().Patch(context.Background(), patchedCluster, client.MergeFrom(cluster))
if k8serrors.IsNotFound(err) {
return
}
nsName := types.NamespacedName{
Name: cluster.Name,
Namespace: cluster.Namespace,
}
Expect(k8sClient.Get(context.Background(), nsName, cluster)).To(Succeed())
}