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
package manifests
import (
"sort"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
"github.com/johnandersen777/socialweb-computer-kcp/api/kcpgvr"
v1alpha1 "github.com/johnandersen777/socialweb-computer-kcp/api/v1alpha1"
)
type WaitKind struct {
Resource schema.GroupVersionResource
Namespaced bool
For map[string]string
}
var WaitKinds = map[string]WaitKind{
"Workspace": {
Resource: kcpgvr.Workspaces,
For: map[string]string{"Ready": CaptureLogicalCluster},
},
"APIExport": {
Resource: kcpgvr.APIExports,
For: map[string]string{"IdentityValid": ""},
},
"APIBinding": {
Resource: kcpgvr.APIBindings,
For: map[string]string{"Ready": ""},
},
"OpenBaoServer": {
Resource: v1alpha1.OpenBaoServerGVR,
For: map[string]string{"Ready": ""},
},
}
func waitKindNames() []string {
out := make([]string, 0, len(WaitKinds))
for k := range WaitKinds {
out = append(out, k)
}
sort.Strings(out)
return out
}
func conditionTrue(u *unstructured.Unstructured, name string) bool {
conds, _, _ := unstructured.NestedSlice(u.Object, "status", "conditions")
for _, c := range conds {
m, ok := c.(map[string]any)
if ok && m["type"] == name && m["status"] == "True" {
return true
}
}
return false
}
func (w Wait) Met(u *unstructured.Unstructured) (bool, string) {
switch w.Kind + "/" + w.For {
case "Workspace/Ready":
phase, _, _ := unstructured.NestedString(u.Object, "status", "phase")
cluster, _, _ := unstructured.NestedString(u.Object, "spec", "cluster")
return phase == "Ready", cluster
case "APIExport/IdentityValid":
return conditionTrue(u, "IdentityValid"), ""
case "APIBinding/Ready":
return conditionTrue(u, "Ready"), ""
case "OpenBaoServer/Ready":
return conditionTrue(u, "Ready"), ""
}
return false, ""
}