-
Notifications
You must be signed in to change notification settings - Fork 5.3k
/
versions.go
43 lines (34 loc) · 1.02 KB
/
versions.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
package fixture
import (
"encoding/json"
"fmt"
"strings"
"github.com/argoproj/gitops-engine/pkg/cache"
"github.com/argoproj/gitops-engine/pkg/utils/kube"
"github.com/argoproj/argo-cd/v2/util/argo"
"github.com/argoproj/argo-cd/v2/util/errors"
kubeutil "github.com/argoproj/argo-cd/v2/util/kube"
)
type Versions struct {
ServerVersion Version
}
type Version struct {
Major, Minor string
}
func (v Version) String() string {
return v.Format("%s.%s")
}
func (v Version) Format(format string) string {
return fmt.Sprintf(format, v.Major, v.Minor)
}
func GetVersions() *Versions {
output := errors.FailOnErr(Run(".", "kubectl", "version", "-o", "json")).(string)
version := &Versions{}
errors.CheckError(json.Unmarshal([]byte(output), version))
return version
}
func GetApiResources() string {
kubectl := kubeutil.NewKubectl()
resources := errors.FailOnErr(kubectl.GetAPIResources(KubeConfig, false, cache.NewNoopSettings())).([]kube.APIResourceInfo)
return strings.Join(argo.APIResourcesToStrings(resources, true), ",")
}