/
params.go
113 lines (101 loc) · 3.69 KB
/
params.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
113
package konnectivity
import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/util/intstr"
hyperv1 "github.com/openshift/hypershift/api/hypershift/v1beta1"
"github.com/openshift/hypershift/control-plane-operator/controllers/hostedcontrolplane/imageprovider"
"github.com/openshift/hypershift/support/config"
)
const (
healthPort = 2041
systemNodeCriticalPriorityClass = "system-node-critical"
)
type KonnectivityParams struct {
KonnectivityAgentImage string
OwnerRef config.OwnerRef
AgentDeploymentConfig config.DeploymentConfig
AgentDeamonSetConfig config.DeploymentConfig
}
func NewKonnectivityParams(hcp *hyperv1.HostedControlPlane, releaseImageProvider *imageprovider.ReleaseImageProvider, externalAddress string, externalPort int32, setDefaultSecurityContext bool) *KonnectivityParams {
p := &KonnectivityParams{
KonnectivityAgentImage: releaseImageProvider.GetImage("konnectivity-agent"),
OwnerRef: config.OwnerRefFrom(hcp),
}
p.AgentDeploymentConfig.Resources = config.ResourcesSpec{
konnectivityAgentContainer().Name: {
Requests: corev1.ResourceList{
corev1.ResourceMemory: resource.MustParse("50Mi"),
corev1.ResourceCPU: resource.MustParse("40m"),
},
},
}
p.AgentDeploymentConfig.Scheduling.PriorityClass = config.DefaultPriorityClass
if hcp.Annotations[hyperv1.ControlPlanePriorityClass] != "" {
p.AgentDeploymentConfig.Scheduling.PriorityClass = hcp.Annotations[hyperv1.ControlPlanePriorityClass]
}
p.AgentDeploymentConfig.LivenessProbes = config.LivenessProbes{
konnectivityAgentContainer().Name: {
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Scheme: corev1.URISchemeHTTP,
Port: intstr.FromInt(int(healthPort)),
Path: "healthz",
},
},
InitialDelaySeconds: 120,
TimeoutSeconds: 30,
PeriodSeconds: 60,
FailureThreshold: 3,
SuccessThreshold: 1,
},
}
p.AgentDeploymentConfig.SetRestartAnnotation(hcp.ObjectMeta)
p.AgentDeploymentConfig.SetDefaults(hcp, konnectivityAgentLabels(), nil)
p.AgentDeamonSetConfig.Resources = config.ResourcesSpec{
konnectivityAgentContainer().Name: {
Requests: corev1.ResourceList{
corev1.ResourceMemory: resource.MustParse("50Mi"),
corev1.ResourceCPU: resource.MustParse("40m"),
},
},
}
p.AgentDeamonSetConfig.Scheduling = config.Scheduling{
PriorityClass: systemNodeCriticalPriorityClass,
}
p.AgentDeamonSetConfig.LivenessProbes = config.LivenessProbes{
konnectivityAgentContainer().Name: {
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Scheme: corev1.URISchemeHTTP,
Port: intstr.FromInt(int(healthPort)),
Path: "healthz",
},
},
InitialDelaySeconds: 120,
TimeoutSeconds: 30,
PeriodSeconds: 60,
FailureThreshold: 3,
SuccessThreshold: 1,
},
}
// non root security context if scc capability is missing
p.AgentDeamonSetConfig.SetDefaultSecurityContext = setDefaultSecurityContext
p.AgentDeploymentConfig.SetDefaultSecurityContext = setDefaultSecurityContext
// check apiserver-network-proxy image in ocp payload and use it
if image, exist := releaseImageProvider.ImageExist("apiserver-network-proxy"); exist {
p.KonnectivityAgentImage = image
}
if _, ok := hcp.Annotations[hyperv1.KonnectivityAgentImageAnnotation]; ok {
p.KonnectivityAgentImage = hcp.Annotations[hyperv1.KonnectivityAgentImageAnnotation]
}
return p
}
type KonnectivityServiceParams struct {
OwnerRef config.OwnerRef
}
func NewKonnectivityServiceParams(hcp *hyperv1.HostedControlPlane) *KonnectivityServiceParams {
return &KonnectivityServiceParams{
OwnerRef: config.OwnerRefFrom(hcp),
}
}