()
| 73 | } |
| 74 | |
| 75 | func detect() (Type, error) { |
| 76 | kubeCfg, err := config.GetConfig() |
| 77 | if err != nil { |
| 78 | return Unsupported, fmt.Errorf("could not get kube config: %w", err) |
| 79 | } |
| 80 | discoveryClient, err := discovery.NewDiscoveryClientForConfig(kubeCfg) |
| 81 | if err != nil { |
| 82 | return Unsupported, fmt.Errorf("could not get discovery client: %w", err) |
| 83 | } |
| 84 | apiList, err := discoveryClient.ServerGroups() |
| 85 | if err != nil { |
| 86 | return Unsupported, fmt.Errorf("could not read API groups: %w", err) |
| 87 | } |
| 88 | if findAPIGroup(apiList.Groups, "route.openshift.io") == nil { |
| 89 | return Kubernetes, nil |
| 90 | } else { |
| 91 | if findAPIGroup(apiList.Groups, "config.openshift.io") == nil { |
| 92 | return Unsupported, nil |
| 93 | } else { |
| 94 | return OpenShiftv4, nil |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | func findAPIGroup(source []metav1.APIGroup, apiName string) *metav1.APIGroup { |
| 100 | for i := 0; i < len(source); i++ { |
no test coverage detected