github.com/caos/orbos@v1.5.14-0.20221103111702-e6cd0cea7ad4/cmd/chore/e2e/run/condition.go (about) 1 package main 2 3 import ( 4 "context" 5 "fmt" 6 "time" 7 8 "github.com/caos/orbos/internal/operator/common" 9 "github.com/caos/orbos/internal/operator/orbiter/kinds/clusters/core/infra" 10 11 "github.com/caos/orbos/internal/operator/orbiter/kinds/clusters/kubernetes" 12 ) 13 14 type conditions struct { 15 kubernetes *kubernetes.Spec 16 testCase *condition 17 boom *condition 18 orbiter *condition 19 } 20 21 func (c *conditions) desiredMasters() uint8 { 22 return uint8(c.kubernetes.ControlPlane.Nodes) 23 } 24 25 func (c *conditions) desiredWorkers() uint8 { 26 var workers uint8 27 for _, pool := range c.kubernetes.Workers { 28 workers += uint8(pool.Nodes) 29 } 30 return workers 31 } 32 33 func zeroConditions() *conditions { return &conditions{kubernetes: &kubernetes.Spec{}} } 34 35 type condition struct { 36 checks checksFunc 37 watcher watcher 38 } 39 40 type checksFunc func(context.Context, newKubectlCommandFunc, currentOrbiter, common.NodeAgentsCurrentKind) error 41 42 type currentOrbiter struct { 43 Clusters map[string]struct { 44 Current kubernetes.CurrentCluster 45 } 46 Providers map[string]struct { 47 Current struct { 48 Ingresses struct { 49 Httpsingress infra.Address 50 Httpingress infra.Address 51 Kubeapi infra.Address 52 } 53 } 54 } 55 } 56 57 func (c *currentOrbiter) cluster(settings programSettings) (cc kubernetes.CurrentCluster, err error) { 58 clusters, ok := c.Clusters[settings.orbID] 59 if !ok { 60 return cc, fmt.Errorf("cluster %s not found in current state", settings.orbID) 61 } 62 return clusters.Current, nil 63 } 64 65 type watcher struct { 66 timeout time.Duration 67 selector string 68 logPrefix operatorPrefix 69 checkWhenLogContains string 70 } 71 72 type operatorPrefix string 73 74 func (o operatorPrefix) strPtr() *string { 75 str := string(o) 76 return &str 77 } 78 79 const ( 80 orbctl operatorPrefix = "orbctl: " 81 orbiter operatorPrefix = "ORBITER: " 82 boom operatorPrefix = "BOOM: " 83 ) 84 85 func watch(timeout time.Duration, operator operatorPrefix) watcher { 86 87 w := watcher{ 88 timeout: timeout, 89 logPrefix: operator, 90 } 91 92 switch operator { 93 case orbiter: 94 w.selector = "app.kubernetes.io/name=orbiter" 95 w.checkWhenLogContains = "Desired state is ensured" 96 case boom: 97 w.selector = "app.kubernetes.io/name=boom" 98 w.checkWhenLogContains = "Iteration done" 99 case orbctl: 100 panic("orbctl must be watched by reading its standard output") 101 } 102 103 return w 104 }