/
apigroup.go
80 lines (68 loc) · 2.29 KB
/
apigroup.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
package apiservice
import (
"context"
"fmt"
"net/http"
"github.com/openshift/library-go/pkg/operator/events"
kubeinformers "k8s.io/client-go/informers"
"k8s.io/client-go/rest"
apiregistrationv1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1"
)
func newEndpointPrecondition(kubeInformers kubeinformers.SharedInformerFactory) func(apiServices []*apiregistrationv1.APIService) (bool, error) {
// this is outside the func so it always registers before the informers start
endpointsLister := kubeInformers.Core().V1().Endpoints().Lister()
type coordinate struct {
namespace string
name string
}
return func(apiServices []*apiregistrationv1.APIService) (bool, error) {
coordinates := []coordinate{}
for _, apiService := range apiServices {
curr := coordinate{namespace: apiService.Spec.Service.Namespace, name: apiService.Spec.Service.Name}
exists := false
for _, j := range coordinates {
if j == curr {
exists = true
break
}
}
if !exists {
coordinates = append(coordinates, curr)
}
}
for _, curr := range coordinates {
endpoints, err := endpointsLister.Endpoints(curr.namespace).Get(curr.name)
if err != nil {
return false, err
}
if len(endpoints.Subsets) == 0 {
return false, nil
}
exists := false
for _, subset := range endpoints.Subsets {
if len(subset.Addresses) > 0 {
exists = true
break
}
}
if !exists {
return false, nil
}
}
return true, nil
}
}
func checkDiscoveryForByAPIServices(recorder events.Recorder, restclient rest.Interface, apiServices []*apiregistrationv1.APIService) []string {
missingMessages := []string{}
for _, apiService := range apiServices {
url := "/apis/" + apiService.Spec.Group + "/" + apiService.Spec.Version
statusCode := 0
result := restclient.Get().AbsPath(url).Do(context.TODO()).StatusCode(&statusCode)
if statusCode != http.StatusOK {
groupVersionString := fmt.Sprintf("%s.%s", apiService.Spec.Group, apiService.Spec.Version)
recorder.Warningf("OpenShiftAPICheckFailed", fmt.Sprintf("%q failed with HTTP status code %d (%v)", groupVersionString, statusCode, result.Error()))
missingMessages = append(missingMessages, fmt.Sprintf("%q is not ready: %d (%v)", groupVersionString, statusCode, result.Error()))
}
}
return missingMessages
}