This repository has been archived by the owner on Jun 14, 2023. It is now read-only.
/
test_object_builder.go
112 lines (94 loc) · 2.76 KB
/
test_object_builder.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package testing
import (
"encoding/json"
"github.com/gardener/landscaper/apis/core/v1alpha1"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
hubv1 "github.com/gardener/potter-controller/api/v1"
"github.com/gardener/potter-controller/pkg/util"
)
func CreateClusterBom(clusterBomName, overallState string) *hubv1.ClusterBom {
testClusterBom := &hubv1.ClusterBom{
ObjectMeta: v1.ObjectMeta{
Name: clusterBomName,
},
Spec: hubv1.ClusterBomSpec{
SecretRef: "testsecret01",
},
Status: hubv1.ClusterBomStatus{
OverallState: overallState,
},
}
return testClusterBom
}
func AddApplicationConfig(clusterBom *hubv1.ClusterBom, id string) {
clusterBom.Spec.ApplicationConfigs = append(clusterBom.Spec.ApplicationConfigs, hubv1.ApplicationConfig{
ID: id,
})
}
func AddApplicationStatus(clusterBom *hubv1.ClusterBom, id, state string, lastOp *hubv1.LastOperation) {
clusterBom.Status.ApplicationStates = append(clusterBom.Status.ApplicationStates, hubv1.ApplicationState{
ID: id,
State: state,
DetailedState: hubv1.DetailedState{
LastOperation: *lastOp,
},
})
}
func CreateDeployItem(clusterBomName, id string, generation, observedGeneration int64, isInstallOperation bool, lastOp *hubv1.LastOperation, readiness *hubv1.Readiness) *v1alpha1.DeployItem {
deployItemConfig := hubv1.HubDeployItemConfiguration{
LocalSecretRef: "asdf",
DeploymentConfig: hubv1.DeploymentConfig{
ID: id,
},
}
encodedConfig, _ := json.Marshal(deployItemConfig)
deployItemProviderStatus := hubv1.HubDeployItemProviderStatus{
LastOperation: *lastOp,
Readiness: readiness,
}
encodedStatus, _ := json.Marshal(deployItemProviderStatus)
result := &v1alpha1.DeployItem{
ObjectMeta: v1.ObjectMeta{
Name: clusterBomName + util.Separator + id,
Labels: map[string]string{
hubv1.LabelClusterBomName: clusterBomName,
hubv1.LabelApplicationConfigID: id,
},
Generation: generation,
},
Spec: v1alpha1.DeployItemSpec{
Type: util.ConfigTypeHelm,
Configuration: &runtime.RawExtension{
Raw: encodedConfig,
},
},
Status: v1alpha1.DeployItemStatus{
ObservedGeneration: observedGeneration,
ProviderStatus: &runtime.RawExtension{
Raw: encodedStatus,
},
},
}
if !isInstallOperation {
now := v1.Now()
result.SetDeletionTimestamp(&now)
}
return result
}
func LastOp(operation string, observedGeneration, successNumber int32, state string, numOfTries int32) hubv1.LastOperation {
return hubv1.LastOperation{
Operation: operation,
SuccessGeneration: int64(successNumber),
State: state,
NumberOfTries: numOfTries,
}
}
func CreateSecret(name string) *corev1.Secret {
return &corev1.Secret{
ObjectMeta: v1.ObjectMeta{
Name: name,
},
}
}