...
1 package linkerd
2
3 import (
4 "fmt"
5 "reflect"
6
7 "github.com/fluxcd/pkg/ssa"
8 "github.com/linkerd/linkerd2/pkg/k8s"
9 corev1 "k8s.io/api/core/v1"
10 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
11 "k8s.io/apimachinery/pkg/labels"
12 "k8s.io/apimachinery/pkg/types"
13 "sigs.k8s.io/controller-runtime/pkg/client"
14
15 "edge-infra.dev/pkg/edge/constants"
16 l5dv1alpha1 "edge-infra.dev/pkg/edge/linkerd/k8s/apis/linkerd/v1alpha1"
17 )
18
19 const (
20
21 Namespace string = "linkerd"
22
23 LinkerdControllerName string = "linkerdctl"
24
25 WorkloadInjectionControllerName string = "linkerdctl-workloadinjection"
26
27 Destination string = "linkerd-destination"
28
29 ProxyInjector string = "linkerd-proxy-injector"
30
31 Identity string = "linkerd-identity"
32
33 TrustAnchorName string = "linkerd-trust-anchor"
34
35 IssuerName string = "linkerd-identity-issuer"
36
37 AdminPort string = "linkerd-admin"
38
39 IdentityCommonName string = "identity.linkerd.cluster.local"
40
41 InjectionAnnotation string = "linkerd.io/inject"
42
43 ProxyVersionAnnotation string = "linkerd.io/proxy-version"
44
45 DefaultReplicaScale int32 = 1
46
47 LinkerdIdentityConfigMap string = "linkerd-identity-trust-roots"
48
49 CertDurationYear int = 2
50 )
51
52 var (
53 ControlPlaneSelector = labels.SelectorFromSet(labels.Set{"linkerd.io/control-plane-ns": Namespace})
54 ControllerContainers = []string{"destination", "sp-validator", "identity", "proxy-injector"}
55 )
56
57 const (
58
59 JSONLogFormat string = "json"
60
61
62
63
64
65
66
67 TraceLogLevel string = "trace"
68 InfoLogLevel string = "info"
69 DebugLogLevel string = "debug"
70 ErrorLogLevel string = "error"
71 WarnLogLevel string = "warn"
72
73
74 IptablesModes string = "nft"
75 )
76
77 const (
78
79
80 DefaultThinPosIdentityIssuerCertificateDurationHours = uint(40)
81
82
83 DefaultThinPosIdentityIssuerCertificateRenewBeforeHours = uint(25)
84
85
86 DefaultThickPosIdentityIssuerCertificateDurationHours = uint(96)
87
88
89 DefaultThickPosIdentityIssuerCertificateRenewBeforeHours = uint(72)
90 )
91
92
93 func TrustAnchorKey() types.NamespacedName {
94 return types.NamespacedName{Name: TrustAnchorName, Namespace: Namespace}
95 }
96
97
98 func IssuerKey() types.NamespacedName {
99 return types.NamespacedName{Name: IssuerName, Namespace: Namespace}
100 }
101
102
103
104
105 func OwnerRef(l5d *l5dv1alpha1.Linkerd) []metav1.OwnerReference {
106 return []metav1.OwnerReference{
107 *metav1.NewControllerRef(
108 l5d,
109 l5dv1alpha1.GroupVersion.WithKind(reflect.TypeOf(l5dv1alpha1.Linkerd{}).Name()),
110 ),
111 }
112 }
113
114
115
116 func CreateOpts() *client.CreateOptions {
117 return &client.CreateOptions{FieldManager: fmt.Sprintf("%s/%s", constants.Domain, LinkerdControllerName)}
118 }
119
120
121 func FilterChanged(changeSet *ssa.ChangeSet) []ssa.ChangeSetEntry {
122 changedEntries := []ssa.ChangeSetEntry{}
123 for _, entry := range changeSet.Entries {
124 if entry.Action != ssa.UnchangedAction {
125 changedEntries = append(changedEntries, entry)
126 }
127 }
128 return changedEntries
129 }
130
131
132 func ProxyContainerStatus(pod *corev1.Pod) *corev1.ContainerStatus {
133 for _, status := range append(pod.Status.ContainerStatuses, pod.Status.InitContainerStatuses...) {
134 if status.Name == k8s.ProxyContainerName {
135 return &status
136 }
137 }
138 return nil
139 }
140
141
142
143 func ProxyExists(pod *corev1.Pod) bool {
144 allContainers := append(pod.Spec.InitContainers, pod.Spec.Containers...)
145 for _, container := range allContainers {
146 if container.Name == k8s.ProxyContainerName {
147 return true
148 }
149 }
150 return false
151 }
152
View as plain text