-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathhealthcheck.go
2560 lines (2317 loc) · 81 KB
/
healthcheck.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package healthcheck
import (
"bufio"
"context"
"crypto/x509"
"errors"
"fmt"
"io"
"sort"
"strings"
"time"
"github.com/linkerd/linkerd2/controller/api/public"
healthcheckPb "github.com/linkerd/linkerd2/controller/gen/common/healthcheck"
configPb "github.com/linkerd/linkerd2/controller/gen/config"
pb "github.com/linkerd/linkerd2/controller/gen/public"
l5dcharts "github.com/linkerd/linkerd2/pkg/charts/linkerd2"
"github.com/linkerd/linkerd2/pkg/config"
"github.com/linkerd/linkerd2/pkg/identity"
"github.com/linkerd/linkerd2/pkg/issuercerts"
"github.com/linkerd/linkerd2/pkg/k8s"
"github.com/linkerd/linkerd2/pkg/multicluster"
"github.com/linkerd/linkerd2/pkg/tls"
"github.com/linkerd/linkerd2/pkg/version"
log "github.com/sirupsen/logrus"
admissionRegistration "k8s.io/api/admissionregistration/v1beta1"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
kerrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
yamlDecoder "k8s.io/apimachinery/pkg/util/yaml"
k8sVersion "k8s.io/apimachinery/pkg/version"
"k8s.io/client-go/kubernetes"
apiregistrationv1client "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/typed/apiregistration/v1"
"sigs.k8s.io/yaml"
)
// CategoryID is an identifier for the types of health checks.
type CategoryID string
const (
// KubernetesAPIChecks adds a series of checks to validate that the caller is
// configured to interact with a working Kubernetes cluster.
KubernetesAPIChecks CategoryID = "kubernetes-api"
// KubernetesVersionChecks validate that the cluster meets the minimum version
// requirements.
KubernetesVersionChecks CategoryID = "kubernetes-version"
// LinkerdPreInstall* checks enabled by `linkerd check --pre`
// LinkerdPreInstallChecks adds checks to validate that the control plane
// namespace does not already exist, and that the user can create cluster-wide
// resources, including ClusterRole, ClusterRoleBinding, and
// CustomResourceDefinition, as well as namespace-wide resources, including
// Service, Deployment, and ConfigMap. This check only runs as part of the set
// of pre-install checks.
// This check is dependent on the output of KubernetesAPIChecks, so those
// checks must be added first.
LinkerdPreInstallChecks CategoryID = "pre-kubernetes-setup"
// LinkerdPreInstallCapabilityChecks adds a check to validate the user has the
// capabilities necessary to deploy Linkerd. For example, the NET_ADMIN and
// NET_RAW capabilities are required by the `linkerd-init` container to modify
// IP tables. These checks are not run when the `--linkerd-cni-enabled` flag
// is set.
LinkerdPreInstallCapabilityChecks CategoryID = "pre-kubernetes-capability"
// LinkerdPreInstallGlobalResourcesChecks adds a series of checks to determine
// the existence of the global resources like cluster roles, cluster role
// bindings, mutating webhook configuration validating webhook configuration
// and pod security policies during the pre-install phase. This check is used
// to determine if a control plane is already installed.
LinkerdPreInstallGlobalResourcesChecks CategoryID = "pre-linkerd-global-resources"
// LinkerdConfigChecks enabled by `linkerd check config`
// LinkerdConfigChecks adds a series of checks to validate that the Linkerd
// namespace, RBAC, ServiceAccounts, and CRDs were successfully created.
// These checks specifically validate that the `linkerd install config`
// command succeeded in a multi-stage install, but also applies to a default
// `linkerd install`.
// These checks are dependent on the output of KubernetesAPIChecks, so those
// checks must be added first.
LinkerdConfigChecks CategoryID = "linkerd-config"
// LinkerdIdentity Checks the integrity of the mTLS certificates
// that the control plane is configured with
LinkerdIdentity CategoryID = "linkerd-identity"
// LinkerdWebhooksAndAPISvcTLS the integrity of the mTLS certificates
// that of the for the injector and sp webhooks and the tap api svc
LinkerdWebhooksAndAPISvcTLS CategoryID = "linkerd-webhooks-and-apisvc-tls"
// LinkerdIdentityDataPlane checks that integrity of the mTLS
// certificates that the proxies are configured with and tries to
// report useful information with respect to whether the configuration
// is compatible with the one of the control plane
LinkerdIdentityDataPlane CategoryID = "linkerd-identity-data-plane"
// LinkerdControlPlaneExistenceChecks adds a series of checks to validate that
// the control plane namespace and controller pod exist.
// These checks are dependent on the output of KubernetesAPIChecks, so those
// checks must be added first.
LinkerdControlPlaneExistenceChecks CategoryID = "linkerd-existence"
// LinkerdAPIChecks adds a series of checks to validate that the control plane
// is successfully serving the public API.
// These checks are dependent on the output of KubernetesAPIChecks, so those
// checks must be added first.
LinkerdAPIChecks CategoryID = "linkerd-api"
// LinkerdVersionChecks adds a series of checks to query for the latest
// version, and validate the CLI is up to date.
LinkerdVersionChecks CategoryID = "linkerd-version"
// LinkerdControlPlaneVersionChecks adds a series of checks to validate that
// the control plane is running the latest available version.
// These checks are dependent on the following:
// 1) `apiClient` from LinkerdControlPlaneExistenceChecks
// 2) `latestVersions` from LinkerdVersionChecks
// 3) `serverVersion` from `LinkerdControlPlaneExistenceChecks`
LinkerdControlPlaneVersionChecks CategoryID = "control-plane-version"
// LinkerdDataPlaneChecks adds data plane checks to validate that the data
// plane namespace exists, and that the proxy containers are in a ready
// state and running the latest available version.
// These checks are dependent on the output of KubernetesAPIChecks,
// `apiClient` from LinkerdControlPlaneExistenceChecks, and `latestVersions`
// from LinkerdVersionChecks, so those checks must be added first.
LinkerdDataPlaneChecks CategoryID = "linkerd-data-plane"
// LinkerdHAChecks adds checks to validate that the HA configuration
// is correct. These checks are no ops if linkerd is not in HA mode
LinkerdHAChecks CategoryID = "linkerd-ha-checks"
// LinkerdCNIPluginChecks adds checks to validate that the CNI
/// plugin is installed and ready
LinkerdCNIPluginChecks CategoryID = "linkerd-cni-plugin"
// LinkerdCNIResourceLabel is the label key that is used to identify
// whether a Kubernetes resource is related to the install-cni command
// The value is expected to be "true", "false" or "", where "false" and
// "" are equal, making "false" the default
LinkerdCNIResourceLabel = "linkerd.io/cni-resource"
linkerdCNIDisabledSkipReason = "skipping check because CNI is not enabled"
linkerdCNIResourceName = "linkerd-cni"
linkerdCNIConfigMapName = "linkerd-cni-config"
// linkerdTapAPIServiceName is the name of the tap api service
// This key is passed to checkApiService method to check whether
// the api service is available or not
linkerdTapAPIServiceName = "v1alpha1.tap.linkerd.io"
tapOldTLSSecretName = "linkerd-tap-tls"
tapTLSSecretName = "linkerd-tap-k8s-tls"
proxyInjectorOldTLSSecretName = "linkerd-proxy-injector-tls"
proxyInjectorTLSSecretName = "linkerd-proxy-injector-k8s-tls"
spValidatorOldTLSSecretName = "linkerd-sp-validator-tls"
spValidatorTLSSecretName = "linkerd-sp-validator-k8s-tls"
certOldKeyName = "crt.pem"
certKeyName = "tls.crt"
keyOldKeyName = "key.pem"
keyKeyName = "tls.key"
)
// HintBaseURL is the base URL on the linkerd.io website that all check hints
// point to. Each check adds its own `hintAnchor` to specify a location on the
// page.
const HintBaseURL = "https://linkerd.io/checks/#"
// AllowedClockSkew sets the allowed skew in clock synchronization
// between the system running inject command and the node(s), being
// based on assumed node's heartbeat interval (5 minutes) plus default TLS
// clock skew allowance.
//
// TODO: Make this default value overridable, e.g. by CLI flag
const AllowedClockSkew = 5*time.Minute + tls.DefaultClockSkewAllowance
var linkerdHAControlPlaneComponents = []string{
"linkerd-controller",
"linkerd-destination",
"linkerd-identity",
"linkerd-proxy-injector",
"linkerd-sp-validator",
"linkerd-tap",
}
// ExpectedServiceAccountNames is a list of the service accounts that a healthy
// Linkerd installation should have. Note that linkerd-heartbeat is optional,
// so it doesn't appear here.
var ExpectedServiceAccountNames = []string{
"linkerd-controller",
"linkerd-destination",
"linkerd-identity",
"linkerd-proxy-injector",
"linkerd-sp-validator",
"linkerd-web",
"linkerd-tap",
}
var (
retryWindow = 5 * time.Second
requestTimeout = 30 * time.Second
)
// Resource provides a way to describe a Kubernetes object, kind, and name.
// TODO: Consider sharing with the inject package's ResourceConfig.workload
// struct, as it wraps both runtime.Object and metav1.TypeMeta.
type Resource struct {
groupVersionKind schema.GroupVersionKind
name string
}
// String outputs the resource in kind.group/name format, intended for
// `linkerd install`.
func (r *Resource) String() string {
return fmt.Sprintf("%s/%s", strings.ToLower(r.groupVersionKind.GroupKind().String()), r.name)
}
// ResourceError provides a custom error type for resource existence checks,
// useful in printing detailed error messages in `linkerd check` and
// `linkerd install`.
type ResourceError struct {
resourceName string
Resources []Resource
}
// Error satisfies the error interface for ResourceError. The output is intended
// for `linkerd check`.
func (e *ResourceError) Error() string {
names := []string{}
for _, res := range e.Resources {
names = append(names, res.name)
}
return fmt.Sprintf("%s found but should not exist: %s", e.resourceName, strings.Join(names, " "))
}
// CategoryError provides a custom error type that also contains check category that emitted the error,
// useful when needed to distinguish between errors from multiple categories
type CategoryError struct {
Category CategoryID
Err error
}
// Error satisfies the error interface for CategoryError.
func (e *CategoryError) Error() string {
return e.Err.Error()
}
// IsCategoryError returns true if passed in error is of type CategoryError and belong to the given category
func IsCategoryError(err error, categoryID CategoryID) bool {
if ce, ok := err.(*CategoryError); ok {
return ce.Category == categoryID
}
return false
}
// SkipError is returned by a check in case this check needs to be ignored.
type SkipError struct {
Reason string
}
// Error satisfies the error interface for SkipError.
func (e *SkipError) Error() string {
return e.Reason
}
// VerboseSuccess implements the error interface but represents a success with
// a message.
type VerboseSuccess struct {
Message string
}
// Error satisfies the error interface for VerboseSuccess. Since VerboseSuccess
// does not actually represent a failure, this returns the empty string.
func (e *VerboseSuccess) Error() string {
return ""
}
type checker struct {
// description is the short description that's printed to the command line
// when the check is executed
description string
// hintAnchor, when appended to `HintBaseURL`, provides a URL to more
// information about the check
hintAnchor string
// fatal indicates that all remaining checks should be aborted if this check
// fails; it should only be used if subsequent checks cannot possibly succeed
// (default false)
fatal bool
// warning indicates that if this check fails, it should be reported, but it
// should not impact the overall outcome of the health check (default false)
warning bool
// retryDeadline establishes a deadline before which this check should be
// retried; if the deadline has passed, the check fails (default: no retries)
retryDeadline time.Time
// surfaceErrorOnRetry indicates that the error message should be displayed
// even if the check will be retried. This is useful if the error message
// contains the current status of the check.
surfaceErrorOnRetry bool
// check is the function that's called to execute the check; if the function
// returns an error, the check fails
check func(context.Context) error
// checkRPC is an alternative to check that can be used to perform a remote
// check using the SelfCheck gRPC endpoint; check status is based on the value
// of the gRPC response
checkRPC func(context.Context) (*healthcheckPb.SelfCheckResponse, error)
}
// CheckResult encapsulates a check's identifying information and output
// Note there exists an analogous user-facing type, `cmd.check`, for output via
// `linkerd check -o json`.
type CheckResult struct {
Category CategoryID
Description string
HintAnchor string
Retry bool
Warning bool
Err error
}
// CheckObserver receives the results of each check.
type CheckObserver func(*CheckResult)
type category struct {
id CategoryID
checkers []checker
enabled bool
}
// Options specifies configuration for a HealthChecker.
type Options struct {
ControlPlaneNamespace string
CNINamespace string
DataPlaneNamespace string
KubeConfig string
KubeContext string
Impersonate string
ImpersonateGroup []string
APIAddr string
VersionOverride string
RetryDeadline time.Time
CNIEnabled bool
InstallManifest string
MultiCluster bool
}
// HealthChecker encapsulates all health check checkers, and clients required to
// perform those checks.
type HealthChecker struct {
categories []category
*Options
// these fields are set in the process of running checks
kubeAPI *k8s.KubernetesAPI
kubeVersion *k8sVersion.Info
controlPlanePods []corev1.Pod
apiClient public.APIClient
latestVersions version.Channels
serverVersion string
linkerdConfig *l5dcharts.Values
uuid string
issuerCert *tls.Cred
trustAnchors []*x509.Certificate
cniDaemonSet *appsv1.DaemonSet
links []multicluster.Link
}
// NewHealthChecker returns an initialized HealthChecker
func NewHealthChecker(categoryIDs []CategoryID, options *Options) *HealthChecker {
hc := &HealthChecker{
Options: options,
}
hc.categories = append(hc.allCategories(), hc.addOnCategories()...)
hc.categories = append(hc.categories, hc.multiClusterCategory()...)
checkMap := map[CategoryID]struct{}{}
for _, category := range categoryIDs {
checkMap[category] = struct{}{}
}
for i := range hc.categories {
if _, ok := checkMap[hc.categories[i].id]; ok {
hc.categories[i].enabled = true
}
}
return hc
}
// allCategories is the global, ordered list of all checkers, grouped by
// category. This method is attached to the HealthChecker struct because the
// checkers directly reference other members of the struct, such as kubeAPI,
// controlPlanePods, etc.
//
// Ordering is important because checks rely on specific `HealthChecker` members
// getting populated by earlier checks, such as kubeAPI, controlPlanePods, etc.
//
// Note that all checks should include a `hintAnchor` with a corresponding section
// in the linkerd check faq:
// https://linkerd.io/checks/#
func (hc *HealthChecker) allCategories() []category {
return []category{
{
id: KubernetesAPIChecks,
checkers: []checker{
{
description: "can initialize the client",
hintAnchor: "k8s-api",
fatal: true,
check: func(context.Context) (err error) {
hc.kubeAPI, err = k8s.NewAPI(hc.KubeConfig, hc.KubeContext, hc.Impersonate, hc.ImpersonateGroup, requestTimeout)
return
},
},
{
description: "can query the Kubernetes API",
hintAnchor: "k8s-api",
fatal: true,
check: func(ctx context.Context) (err error) {
hc.kubeVersion, err = hc.kubeAPI.GetVersionInfo()
return
},
},
},
},
{
id: KubernetesVersionChecks,
checkers: []checker{
{
description: "is running the minimum Kubernetes API version",
hintAnchor: "k8s-version",
check: func(context.Context) error {
return hc.kubeAPI.CheckVersion(hc.kubeVersion)
},
},
{
description: "is running the minimum kubectl version",
hintAnchor: "kubectl-version",
check: func(context.Context) error {
return k8s.CheckKubectlVersion()
},
},
},
},
{
id: LinkerdPreInstallChecks,
checkers: []checker{
{
description: "control plane namespace does not already exist",
hintAnchor: "pre-ns",
check: func(ctx context.Context) error {
return hc.checkNamespace(ctx, hc.ControlPlaneNamespace, false)
},
},
{
description: "can create non-namespaced resources",
hintAnchor: "pre-k8s-cluster-k8s",
check: func(ctx context.Context) error {
return hc.checkCanCreateNonNamespacedResources(ctx)
},
},
{
description: "can create ServiceAccounts",
hintAnchor: "pre-k8s",
check: func(ctx context.Context) error {
return hc.checkCanCreate(ctx, hc.ControlPlaneNamespace, "", "v1", "serviceaccounts")
},
},
{
description: "can create Services",
hintAnchor: "pre-k8s",
check: func(ctx context.Context) error {
return hc.checkCanCreate(ctx, hc.ControlPlaneNamespace, "", "v1", "services")
},
},
{
description: "can create Deployments",
hintAnchor: "pre-k8s",
check: func(ctx context.Context) error {
return hc.checkCanCreate(ctx, hc.ControlPlaneNamespace, "apps", "v1", "deployments")
},
},
{
description: "can create CronJobs",
hintAnchor: "pre-k8s",
check: func(ctx context.Context) error {
return hc.checkCanCreate(ctx, hc.ControlPlaneNamespace, "batch", "v1beta1", "cronjobs")
},
},
{
description: "can create ConfigMaps",
hintAnchor: "pre-k8s",
check: func(ctx context.Context) error {
return hc.checkCanCreate(ctx, hc.ControlPlaneNamespace, "", "v1", "configmaps")
},
},
{
description: "can create Secrets",
hintAnchor: "pre-k8s",
check: func(ctx context.Context) error {
return hc.checkCanCreate(ctx, hc.ControlPlaneNamespace, "", "v1", "secrets")
},
},
{
description: "can read Secrets",
hintAnchor: "pre-k8s",
check: func(ctx context.Context) error {
return hc.checkCanGet(ctx, hc.ControlPlaneNamespace, "", "v1", "secrets")
},
},
{
description: "can read extension-apiserver-authentication configmap",
hintAnchor: "pre-k8s",
check: func(ctx context.Context) error {
return hc.checkExtensionAPIServerAuthentication(ctx)
},
},
{
description: "no clock skew detected",
hintAnchor: "pre-k8s-clock-skew",
warning: true,
check: func(ctx context.Context) error {
return hc.checkClockSkew(ctx)
},
},
},
},
{
id: LinkerdPreInstallCapabilityChecks,
checkers: []checker{
{
description: "has NET_ADMIN capability",
hintAnchor: "pre-k8s-cluster-net-admin",
warning: true,
check: func(ctx context.Context) error {
return hc.checkCapability(ctx, "NET_ADMIN")
},
},
{
description: "has NET_RAW capability",
hintAnchor: "pre-k8s-cluster-net-raw",
warning: true,
check: func(ctx context.Context) error {
return hc.checkCapability(ctx, "NET_RAW")
},
},
},
},
{
id: LinkerdPreInstallGlobalResourcesChecks,
checkers: []checker{
{
description: "no ClusterRoles exist",
hintAnchor: "pre-l5d-existence",
check: func(ctx context.Context) error {
return hc.checkClusterRoles(ctx, false, hc.expectedRBACNames(), hc.controlPlaneComponentsSelector())
},
},
{
description: "no ClusterRoleBindings exist",
hintAnchor: "pre-l5d-existence",
check: func(ctx context.Context) error {
return hc.checkClusterRoleBindings(ctx, false, hc.expectedRBACNames(), hc.controlPlaneComponentsSelector())
},
},
{
description: "no CustomResourceDefinitions exist",
hintAnchor: "pre-l5d-existence",
check: func(ctx context.Context) error {
return hc.checkCustomResourceDefinitions(ctx, false)
},
},
{
description: "no MutatingWebhookConfigurations exist",
hintAnchor: "pre-l5d-existence",
check: func(ctx context.Context) error {
return hc.checkMutatingWebhookConfigurations(ctx, false)
},
},
{
description: "no ValidatingWebhookConfigurations exist",
hintAnchor: "pre-l5d-existence",
check: func(ctx context.Context) error {
return hc.checkValidatingWebhookConfigurations(ctx, false)
},
},
{
description: "no PodSecurityPolicies exist",
hintAnchor: "pre-l5d-existence",
check: func(ctx context.Context) error {
return hc.checkPodSecurityPolicies(ctx, false)
},
},
},
},
{
id: LinkerdControlPlaneExistenceChecks,
checkers: []checker{
{
description: "'linkerd-config' config map exists",
hintAnchor: "l5d-existence-linkerd-config",
fatal: true,
check: func(ctx context.Context) (err error) {
hc.uuid, hc.linkerdConfig, err = hc.checkLinkerdConfigConfigMap(ctx)
if hc.linkerdConfig != nil {
hc.CNIEnabled = hc.linkerdConfig.Global.CNIEnabled
}
return
},
},
{
description: "heartbeat ServiceAccount exist",
hintAnchor: "l5d-existence-sa",
fatal: true,
check: func(ctx context.Context) error {
if hc.isHeartbeatDisabled() {
return nil
}
return hc.checkServiceAccounts(ctx, []string{"linkerd-heartbeat"}, hc.ControlPlaneNamespace, hc.controlPlaneComponentsSelector())
},
},
{
description: "control plane replica sets are ready",
hintAnchor: "l5d-existence-replicasets",
retryDeadline: hc.RetryDeadline,
fatal: true,
check: func(ctx context.Context) error {
controlPlaneReplicaSet, err := hc.kubeAPI.GetReplicaSets(ctx, hc.ControlPlaneNamespace)
if err != nil {
return err
}
return checkControlPlaneReplicaSets(controlPlaneReplicaSet)
},
},
{
description: "no unschedulable pods",
hintAnchor: "l5d-existence-unschedulable-pods",
retryDeadline: hc.RetryDeadline,
surfaceErrorOnRetry: true,
warning: true,
check: func(ctx context.Context) error {
// do not save this into hc.controlPlanePods, as this check may
// succeed prior to all expected control plane pods being up
controlPlanePods, err := hc.kubeAPI.GetPodsByNamespace(ctx, hc.ControlPlaneNamespace)
if err != nil {
return err
}
return checkUnschedulablePods(controlPlanePods)
},
},
{
description: "controller pod is running",
hintAnchor: "l5d-existence-controller",
retryDeadline: hc.RetryDeadline,
surfaceErrorOnRetry: true,
fatal: true,
check: func(ctx context.Context) error {
// save this into hc.controlPlanePods, since this check only
// succeeds when all pods are up
var err error
hc.controlPlanePods, err = hc.kubeAPI.GetPodsByNamespace(ctx, hc.ControlPlaneNamespace)
if err != nil {
return err
}
return checkContainerRunning(hc.controlPlanePods, "controller")
},
},
{
description: "can initialize the client",
hintAnchor: "l5d-existence-client",
fatal: true,
check: func(ctx context.Context) (err error) {
if hc.APIAddr != "" {
hc.apiClient, err = public.NewInternalClient(hc.ControlPlaneNamespace, hc.APIAddr)
} else {
hc.apiClient, err = public.NewExternalClient(ctx, hc.ControlPlaneNamespace, hc.kubeAPI)
}
return
},
},
{
description: "can query the control plane API",
hintAnchor: "l5d-existence-api",
retryDeadline: hc.RetryDeadline,
fatal: true,
check: func(ctx context.Context) (err error) {
hc.serverVersion, err = GetServerVersion(ctx, hc.apiClient)
return
},
},
},
},
{
id: LinkerdConfigChecks,
checkers: []checker{
{
description: "control plane Namespace exists",
hintAnchor: "l5d-existence-ns",
fatal: true,
check: func(ctx context.Context) error {
return hc.checkNamespace(ctx, hc.ControlPlaneNamespace, true)
},
},
{
description: "control plane ClusterRoles exist",
hintAnchor: "l5d-existence-cr",
fatal: true,
check: func(ctx context.Context) error {
return hc.checkClusterRoles(ctx, true, hc.expectedRBACNames(), hc.controlPlaneComponentsSelector())
},
},
{
description: "control plane ClusterRoleBindings exist",
hintAnchor: "l5d-existence-crb",
fatal: true,
check: func(ctx context.Context) error {
return hc.checkClusterRoleBindings(ctx, true, hc.expectedRBACNames(), hc.controlPlaneComponentsSelector())
},
},
{
description: "control plane ServiceAccounts exist",
hintAnchor: "l5d-existence-sa",
fatal: true,
check: func(ctx context.Context) error {
return hc.checkServiceAccounts(ctx, ExpectedServiceAccountNames, hc.ControlPlaneNamespace, hc.controlPlaneComponentsSelector())
},
},
{
description: "control plane CustomResourceDefinitions exist",
hintAnchor: "l5d-existence-crd",
fatal: true,
check: func(ctx context.Context) error {
return hc.checkCustomResourceDefinitions(ctx, true)
},
},
{
description: "control plane MutatingWebhookConfigurations exist",
hintAnchor: "l5d-existence-mwc",
fatal: true,
check: func(ctx context.Context) error {
return hc.checkMutatingWebhookConfigurations(ctx, true)
},
},
{
description: "control plane ValidatingWebhookConfigurations exist",
hintAnchor: "l5d-existence-vwc",
fatal: true,
check: func(ctx context.Context) error {
return hc.checkValidatingWebhookConfigurations(ctx, true)
},
},
{
description: "control plane PodSecurityPolicies exist",
hintAnchor: "l5d-existence-psp",
fatal: true,
check: func(ctx context.Context) error {
return hc.checkPodSecurityPolicies(ctx, true)
},
},
},
},
{
id: LinkerdCNIPluginChecks,
checkers: []checker{
{
description: "cni plugin ConfigMap exists",
hintAnchor: "cni-plugin-cm-exists",
fatal: true,
check: func(ctx context.Context) error {
if !hc.CNIEnabled {
return &SkipError{Reason: linkerdCNIDisabledSkipReason}
}
_, err := hc.kubeAPI.CoreV1().ConfigMaps(hc.CNINamespace).Get(ctx, linkerdCNIConfigMapName, metav1.GetOptions{})
return err
},
},
{
description: "cni plugin PodSecurityPolicy exists",
hintAnchor: "cni-plugin-psp-exists",
fatal: true,
check: func(ctx context.Context) error {
if !hc.CNIEnabled {
return &SkipError{Reason: linkerdCNIDisabledSkipReason}
}
pspName := fmt.Sprintf("linkerd-%s-cni", hc.CNINamespace)
_, err := hc.kubeAPI.PolicyV1beta1().PodSecurityPolicies().Get(ctx, pspName, metav1.GetOptions{})
if kerrors.IsNotFound(err) {
return fmt.Errorf("missing PodSecurityPolicy: %s", pspName)
}
return err
},
},
{
description: "cni plugin ClusterRole exists",
hintAnchor: "cni-plugin-cr-exists",
fatal: true,
check: func(ctx context.Context) error {
if !hc.CNIEnabled {
return &SkipError{Reason: linkerdCNIDisabledSkipReason}
}
_, err := hc.kubeAPI.RbacV1().ClusterRoles().Get(ctx, linkerdCNIResourceName, metav1.GetOptions{})
if kerrors.IsNotFound(err) {
return fmt.Errorf("missing ClusterRole: %s", linkerdCNIResourceName)
}
return err
},
},
{
description: "cni plugin ClusterRoleBinding exists",
hintAnchor: "cni-plugin-crb-exists",
fatal: true,
check: func(ctx context.Context) error {
if !hc.CNIEnabled {
return &SkipError{Reason: linkerdCNIDisabledSkipReason}
}
_, err := hc.kubeAPI.RbacV1().ClusterRoleBindings().Get(ctx, linkerdCNIResourceName, metav1.GetOptions{})
if kerrors.IsNotFound(err) {
return fmt.Errorf("missing ClusterRoleBinding: %s", linkerdCNIResourceName)
}
return err
},
},
{
description: "cni plugin Role exists",
hintAnchor: "cni-plugin-r-exists",
fatal: true,
check: func(ctx context.Context) error {
if !hc.CNIEnabled {
return &SkipError{Reason: linkerdCNIDisabledSkipReason}
}
_, err := hc.kubeAPI.RbacV1().Roles(hc.CNINamespace).Get(ctx, linkerdCNIResourceName, metav1.GetOptions{})
if kerrors.IsNotFound(err) {
return fmt.Errorf("missing Role: %s", linkerdCNIResourceName)
}
return err
},
},
{
description: "cni plugin RoleBinding exists",
hintAnchor: "cni-plugin-rb-exists",
fatal: true,
check: func(ctx context.Context) error {
if !hc.CNIEnabled {
return &SkipError{Reason: linkerdCNIDisabledSkipReason}
}
_, err := hc.kubeAPI.RbacV1().RoleBindings(hc.CNINamespace).Get(ctx, linkerdCNIResourceName, metav1.GetOptions{})
if kerrors.IsNotFound(err) {
return fmt.Errorf("missing RoleBinding: %s", linkerdCNIResourceName)
}
return err
},
},
{
description: "cni plugin ServiceAccount exists",
hintAnchor: "cni-plugin-sa-exists",
fatal: true,
check: func(ctx context.Context) error {
if !hc.CNIEnabled {
return &SkipError{Reason: linkerdCNIDisabledSkipReason}
}
_, err := hc.kubeAPI.CoreV1().ServiceAccounts(hc.CNINamespace).Get(ctx, linkerdCNIResourceName, metav1.GetOptions{})
if kerrors.IsNotFound(err) {
return fmt.Errorf("missing ServiceAccount: %s", linkerdCNIResourceName)
}
return err
},
},
{
description: "cni plugin DaemonSet exists",
hintAnchor: "cni-plugin-ds-exists",
fatal: true,
check: func(ctx context.Context) (err error) {
if !hc.CNIEnabled {
return &SkipError{Reason: linkerdCNIDisabledSkipReason}
}
hc.cniDaemonSet, err = hc.kubeAPI.Interface.AppsV1().DaemonSets(hc.CNINamespace).Get(ctx, linkerdCNIResourceName, metav1.GetOptions{})
if kerrors.IsNotFound(err) {
return fmt.Errorf("missing DaemonSet: %s", linkerdCNIResourceName)
}
return err
},
},
{
description: "cni plugin pod is running on all nodes",
hintAnchor: "cni-plugin-ready",
retryDeadline: hc.RetryDeadline,
surfaceErrorOnRetry: true,
fatal: true,
check: func(ctx context.Context) (err error) {
if !hc.CNIEnabled {
return &SkipError{Reason: linkerdCNIDisabledSkipReason}
}
hc.cniDaemonSet, err = hc.kubeAPI.Interface.AppsV1().DaemonSets(hc.CNINamespace).Get(ctx, linkerdCNIResourceName, metav1.GetOptions{})
if kerrors.IsNotFound(err) {
return fmt.Errorf("missing DaemonSet: %s", linkerdCNIResourceName)
}
scheduled := hc.cniDaemonSet.Status.DesiredNumberScheduled
ready := hc.cniDaemonSet.Status.NumberReady
if scheduled != ready {
return fmt.Errorf("number ready: %d, number scheduled: %d", ready, scheduled)
}
return nil
},
},
},
},
{
id: LinkerdIdentity,
checkers: []checker{
{
description: "certificate config is valid",
hintAnchor: "l5d-identity-cert-config-valid",
fatal: true,
check: func(ctx context.Context) (err error) {
hc.issuerCert, hc.trustAnchors, err = hc.checkCertificatesConfig(ctx)
return
},
},
{
description: "trust anchors are using supported crypto algorithm",
hintAnchor: "l5d-identity-trustAnchors-use-supported-crypto",
fatal: true,
check: func(context.Context) error {
var invalidAnchors []string
for _, anchor := range hc.trustAnchors {
if err := issuercerts.CheckCertAlgoRequirements(anchor); err != nil {
invalidAnchors = append(invalidAnchors, fmt.Sprintf("* %v %s %s", anchor.SerialNumber, anchor.Subject.CommonName, err))
}
}
if len(invalidAnchors) > 0 {
return fmt.Errorf("Invalid trustAnchors:\n\t%s", strings.Join(invalidAnchors, "\n\t"))
}
return nil
},
},
{
description: "trust anchors are within their validity period",
hintAnchor: "l5d-identity-trustAnchors-are-time-valid",
fatal: true,
check: func(ctx context.Context) error {
var expiredAnchors []string
for _, anchor := range hc.trustAnchors {
if err := issuercerts.CheckCertValidityPeriod(anchor); err != nil {
expiredAnchors = append(expiredAnchors, fmt.Sprintf("* %v %s %s", anchor.SerialNumber, anchor.Subject.CommonName, err))
}
}
if len(expiredAnchors) > 0 {
return fmt.Errorf("Invalid anchors:\n\t%s", strings.Join(expiredAnchors, "\n\t"))
}
return nil
},
},
{
description: "trust anchors are valid for at least 60 days",
hintAnchor: "l5d-identity-trustAnchors-not-expiring-soon",
warning: true,
check: func(ctx context.Context) error {
var expiringAnchors []string
for _, anchor := range hc.trustAnchors {
if err := issuercerts.CheckExpiringSoon(anchor); err != nil {
expiringAnchors = append(expiringAnchors, fmt.Sprintf("* %v %s %s", anchor.SerialNumber, anchor.Subject.CommonName, err))
}
}
if len(expiringAnchors) > 0 {
return fmt.Errorf("Anchors expiring soon:\n\t%s", strings.Join(expiringAnchors, "\n\t"))
}
return nil
},
},
{
description: "issuer cert is using supported crypto algorithm",
hintAnchor: "l5d-identity-issuer-cert-uses-supported-crypto",
fatal: true,
check: func(context.Context) error {
if err := issuercerts.CheckCertAlgoRequirements(hc.issuerCert.Certificate); err != nil {
return fmt.Errorf("issuer certificate %s", err)
}
return nil
},
},
{
description: "issuer cert is within its validity period",