This repository has been archived by the owner on Sep 16, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
util.go
68 lines (49 loc) · 1.58 KB
/
util.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
package deprecation
import (
"encoding/json"
"fmt"
"io/ioutil"
semver "github.com/Masterminds/semver/v3"
"github.com/ckotzbauer/chekr/pkg/util"
"github.com/sirupsen/logrus"
)
var ignoredDeprecatedKinds = []string{"Event"}
func fetchDeprecatedApis() []GroupVersion {
file, err := ioutil.TempFile("", "k8s_deprecation")
if err != nil {
logrus.WithError(err).Fatalf("Could not create temp-file!")
}
err = util.DownloadFile(
file.Name(),
"https://raw.githubusercontent.com/ckotzbauer/chekr/main/data/k8s_deprecations_generated.json")
if err != nil {
logrus.WithError(err).Fatalf("Could not download deprecation-definition!")
}
buf, err := ioutil.ReadFile(file.Name())
if err != nil {
logrus.WithError(err).Fatalf("Could not read deprecation-definition!")
}
data := []GroupVersion{}
err = json.Unmarshal([]byte(buf), &data)
if err != nil {
logrus.WithError(err).Fatalf("Could not unmarshal deprecation-definition!")
}
return data
}
func (d Deprecation) isVersionIgnored(deprecation string) bool {
if d.K8sVersion == "" {
info, err := d.KubeClient.Client.ServerVersion()
if err == nil && info != nil {
d.K8sVersion = fmt.Sprintf("%s.%s", info.Major, info.Minor)
}
}
c, err := semver.NewConstraint("< " + deprecation)
if err != nil {
logrus.WithError(err).WithField("constraint", "< "+deprecation).Fatalf("Could not parse version-constraint!")
}
v, err := semver.NewVersion(d.K8sVersion)
if err != nil {
logrus.WithError(err).WithField("version1", deprecation).WithField("version2", d.K8sVersion).Fatalf("Could not compare versions!")
}
return c.Check(v)
}