This repository has been archived by the owner on Apr 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
containers.go
96 lines (77 loc) · 2.57 KB
/
containers.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
package pod
import (
"fmt"
v1 "k8s.io/api/core/v1"
"github.com/openservicemesh/osm-health/pkg/common"
"github.com/openservicemesh/osm-health/pkg/kuberneteshelper"
)
// Verify interface compliance
var _ common.Runnable = (*EnvoySidecarImageCheck)(nil)
// EnvoySidecarImageCheck implements common.Runnable
type EnvoySidecarImageCheck struct {
pod *v1.Pod
}
// HasExpectedEnvoyImage checks whether a pod has a sidecar with the envoy image specified in the meshconfig
func HasExpectedEnvoyImage(pod *v1.Pod) EnvoySidecarImageCheck {
return EnvoySidecarImageCheck{
pod: pod,
}
}
// Info implements common.Runnable
func (check EnvoySidecarImageCheck) Info() string {
return fmt.Sprintf("Checking whether pod %s has a container with envoy image matching meshconfig envoy image", check.pod.Name)
}
// Run implements common.Runnable
func (check EnvoySidecarImageCheck) Run() error {
cfg := kuberneteshelper.GetOsmConfigurator(check.pod)
for _, container := range check.pod.Spec.Containers {
if container.Image == cfg.GetEnvoyImage() {
return nil
}
}
return ErrExpectedEnvoyImageMissing
}
// Verify interface compliance
var _ common.Runnable = (*MinNumContainersCheck)(nil)
// Suggestion implements common.Runnable
func (check EnvoySidecarImageCheck) Suggestion() string {
panic("implement me")
}
// FixIt implements common.Runnable
func (check EnvoySidecarImageCheck) FixIt() error {
panic("implement me")
}
// Verify interface compliance
var _ common.Runnable = (*MinNumContainersCheck)(nil)
// MinNumContainersCheck implements common.Runnable
type MinNumContainersCheck struct {
pod *v1.Pod
minNum int
}
// HasMinExpectedContainers checks whether a pod has at least the min number of containers expected
// This currently corresponds to an app container, osm init container and envoy proxy sidecar
func HasMinExpectedContainers(pod *v1.Pod, num int) MinNumContainersCheck {
return MinNumContainersCheck{
pod: pod,
minNum: num,
}
}
// Info implements common.Runnable
func (check MinNumContainersCheck) Info() string {
return fmt.Sprintf("Checking whether pod %s has at least %d containers", check.pod.Name, check.minNum)
}
// Run implements common.Runnable
func (check MinNumContainersCheck) Run() error {
if len(check.pod.Spec.Containers)+len(check.pod.Spec.InitContainers) < check.minNum {
return ErrExpectedMinNumContainers
}
return nil
}
// Suggestion implements common.Runnable
func (check MinNumContainersCheck) Suggestion() string {
panic("implement me")
}
// FixIt implements common.Runnable
func (check MinNumContainersCheck) FixIt() error {
panic("implement me")
}