-
Notifications
You must be signed in to change notification settings - Fork 64
/
route_agent_resources.go
158 lines (147 loc) · 6.23 KB
/
route_agent_resources.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
SPDX-License-Identifier: Apache-2.0
Copyright Contributors to the Submariner project.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package submariner
import (
"context"
"strconv"
"github.com/go-logr/logr"
"github.com/submariner-io/admiral/pkg/names"
"github.com/submariner-io/submariner-operator/api/v1alpha1"
"github.com/submariner-io/submariner-operator/controllers/apply"
"github.com/submariner-io/submariner-operator/pkg/images"
opnames "github.com/submariner-io/submariner-operator/pkg/names"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/utils/ptr"
)
//nolint:wrapcheck // No need to wrap errors here.
func (r *Reconciler) reconcileRouteagentDaemonSet(ctx context.Context, instance *v1alpha1.Submariner,
reqLogger logr.Logger,
) (*appsv1.DaemonSet, error) {
return apply.DaemonSet(ctx, instance, newRouteAgentDaemonSet(instance, names.RouteAgentComponent),
reqLogger, r.config.ScopedClient, r.config.Scheme)
}
func newRouteAgentDaemonSet(cr *v1alpha1.Submariner, name string) *appsv1.DaemonSet {
labels := map[string]string{
"app": name,
"component": "routeagent",
}
maxUnavailable := intstr.FromString("100%")
ds := &appsv1.DaemonSet{
ObjectMeta: metav1.ObjectMeta{
Namespace: cr.Namespace,
Name: name,
Labels: labels,
},
Spec: appsv1.DaemonSetSpec{
Selector: &metav1.LabelSelector{MatchLabels: map[string]string{
"app": name,
}},
UpdateStrategy: appsv1.DaemonSetUpdateStrategy{
RollingUpdate: &appsv1.RollingUpdateDaemonSet{
MaxUnavailable: &maxUnavailable,
},
Type: appsv1.RollingUpdateDaemonSetStrategyType,
},
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: labels,
},
Spec: corev1.PodSpec{
TerminationGracePeriodSeconds: ptr.To(int64(1)),
Volumes: []corev1.Volume{
// Share /run/xtables.lock with the host for iptables
{Name: "host-run-xtables-lock", VolumeSource: corev1.VolumeSource{HostPath: &corev1.HostPathVolumeSource{
Path: "/run/xtables.lock",
}}},
// Share /run/openvswitch/db.sock and /run/openvswitch/ovnnb_db.sock with the host for OVS/OVN
{Name: "host-run-openvswitch", VolumeSource: corev1.VolumeSource{HostPath: &corev1.HostPathVolumeSource{
Path: "/run/openvswitch", Type: ptr.To(corev1.HostPathDirectoryOrCreate),
}}},
// Share /sys with the host for OVS/OVN
{Name: "host-sys", VolumeSource: corev1.VolumeSource{HostPath: &corev1.HostPathVolumeSource{
Path: "/sys",
}}},
// Share /run/ovn-ic with the host for OVN (this is a transitional path used by OpenShift for upgrades)
{Name: "host-run-ovn-ic", VolumeSource: corev1.VolumeSource{HostPath: &corev1.HostPathVolumeSource{
Path: "/run/ovn-ic", Type: ptr.To(corev1.HostPathDirectoryOrCreate),
}}},
},
// The route agent needs to wait for the node to be ready before starting,
// to avoid racing with the CNI for socket setup; this init container takes care of that
InitContainers: []corev1.Container{
{
Name: name + "-init",
Image: getImagePath(cr, opnames.RouteAgentImage, names.RouteAgentComponent),
ImagePullPolicy: images.GetPullPolicy(cr.Spec.Version, cr.Spec.ImageOverrides[names.RouteAgentComponent]),
Command: []string{"submariner-route-agent.sh"},
Env: []corev1.EnvVar{
{Name: "SUBMARINER_WAITFORNODE", Value: "true"},
{Name: "NODE_NAME", ValueFrom: &corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{
FieldPath: "spec.nodeName",
},
}},
},
},
},
Containers: []corev1.Container{
{
Name: name,
Image: getImagePath(cr, opnames.RouteAgentImage, names.RouteAgentComponent),
ImagePullPolicy: images.GetPullPolicy(cr.Spec.Version, cr.Spec.ImageOverrides[names.RouteAgentComponent]),
// FIXME: Should be entrypoint script, find/use correct file for routeagent
Command: []string{"submariner-route-agent.sh"},
SecurityContext: &corev1.SecurityContext{
Capabilities: &corev1.Capabilities{Add: []corev1.Capability{"ALL"}},
AllowPrivilegeEscalation: ptr.To(true),
Privileged: ptr.To(true),
ReadOnlyRootFilesystem: ptr.To(false),
RunAsNonRoot: ptr.To(false),
},
VolumeMounts: []corev1.VolumeMount{
{Name: "host-sys", MountPath: "/sys", ReadOnly: true},
{Name: "host-run-xtables-lock", MountPath: "/run/xtables.lock"},
{Name: "host-run-openvswitch", MountPath: "/run/openvswitch"},
{Name: "host-run-ovn-ic", MountPath: "/run/ovn-ic"},
},
Env: []corev1.EnvVar{
{Name: "SUBMARINER_NAMESPACE", Value: cr.Spec.Namespace},
{Name: "SUBMARINER_CLUSTERID", Value: cr.Spec.ClusterID},
{Name: "SUBMARINER_DEBUG", Value: strconv.FormatBool(cr.Spec.Debug)},
{Name: "SUBMARINER_CLUSTERCIDR", Value: cr.Status.ClusterCIDR},
{Name: "SUBMARINER_SERVICECIDR", Value: cr.Status.ServiceCIDR},
{Name: "SUBMARINER_GLOBALCIDR", Value: cr.Spec.GlobalCIDR},
{Name: "SUBMARINER_NETWORKPLUGIN", Value: cr.Status.NetworkPlugin},
{Name: "NODE_NAME", ValueFrom: &corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{
FieldPath: "spec.nodeName",
},
}},
},
},
},
ServiceAccountName: names.RouteAgentComponent,
HostNetwork: true,
DNSPolicy: corev1.DNSClusterFirstWithHostNet,
// The route agent engine on all nodes, regardless of existing taints
Tolerations: []corev1.Toleration{{Operator: corev1.TolerationOpExists}},
},
},
},
}
return ds
}