-
Notifications
You must be signed in to change notification settings - Fork 0
/
endpoint_investigator.go
64 lines (56 loc) · 1.91 KB
/
endpoint_investigator.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
/*
* Copyright FMR LLC <opensource@fidelity.com>
*
* SPDX-License-Identifier: Apache
*/
package investigators
import (
"context"
"sync"
"github.com/fidelity/theliv/internal/problem"
com "github.com/fidelity/theliv/pkg/common"
"github.com/fidelity/theliv/pkg/kubeclient"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
const (
NotReadyAddressSolution = `
1. At least one subset has 'NotReadyAddresses' status.
2. Please check the health of the selected pods.
`
NoPodSelectedSolution = `
1. There are no pods that match the service selector(s):{{range $index, $value := .Spec.Selector}}
- {{$index}}: {{$value}}{{end}}
2. Please set the service selector or add endpoint subsets properly.
`
NoServiceFoundSolution = `
1. No Service or subsets found for Endpoint {{.Name}}.
2. Please check if this Endpoint is necessary.
`
)
func EndpointAddressNotAvailableInvestigator(ctx context.Context, wg *sync.WaitGroup,
problem *problem.Problem, input *problem.DetectorCreationInput) {
defer wg.Done()
var solutions []string
endpoint := *problem.AffectedResources.Resource.(*v1.Endpoints)
svc := &v1.Service{}
namespace := kubeclient.NamespacedName{
Namespace: endpoint.Namespace,
Name: endpoint.Name,
}
if input.KubeClient.Get(ctx, svc, namespace, metav1.GetOptions{}) == nil {
logChecking(ctx, com.Service+com.Blank+svc.Name)
problem.AffectedResources.ResourceKind = com.Service
problem.AffectedResources.Resource = svc
} else {
logChecking(ctx, com.Endpoint+com.Blank+endpoint.Name)
appendSolution(problem,
GetSolutionsByTemplate(ctx, NoServiceFoundSolution, endpoint, true), nil)
}
if len(endpoint.Subsets) != 0 {
solutions = GetSolutionsByTemplate(ctx, NotReadyAddressSolution, svc, true)
} else {
solutions = GetSolutionsByTemplate(ctx, NoPodSelectedSolution, svc, true)
}
appendSolution(problem, solutions, GetSolutionsByTemplate(ctx, GetEndpointsCmd, endpoint, true))
}