Skip to content

Commit

Permalink
BUG/MEDIUM: crd: fix checking of existing CRD definitions in k8s
Browse files Browse the repository at this point in the history
  • Loading branch information
oktalz committed Mar 14, 2024
1 parent f1dfd91 commit 6f6bf4c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions crs/definition/embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ var Backends []byte

func GetCRDs() map[string][]byte {
return map[string][]byte{
"ingress.v1.haproxy.org_defaults.yaml": Defaults,
"ingress.v1.haproxy.org_globals.yaml": Globals,
"ingress.v1.haproxy.org_backends.yaml": Backends,
"defaults.ingress.v1.haproxy.org": Defaults,
"globals.ingress.v1.haproxy.org": Globals,
"backends.ingress.v1.haproxy.org": Backends,
}
}
6 changes: 3 additions & 3 deletions pkg/job/crd-check.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
)

func CRDRefresh(log utils.Logger, osArgs utils.OSArgs) error {
log.Info("checking CRDS")
log.Info("checking CRDs")
config, err := k8s.GetRestConfig(osArgs)
if err != nil {
return err
Expand Down Expand Up @@ -72,7 +72,6 @@ func CRDRefresh(log utils.Logger, osArgs utils.OSArgs) error {
// check if we have v1 and newest version
crd.ObjectMeta.ResourceVersion = existingVersion.ObjectMeta.ResourceVersion
if versions[0].Name == "v1" {
log.Infof("CRD %s exists as v1", crdName)
cnInK8s, ok := existingVersion.ObjectMeta.Annotations["haproxy.org/client-native"]

needUpgrade := false
Expand All @@ -90,13 +89,14 @@ func CRDRefresh(log utils.Logger, osArgs utils.OSArgs) error {
needUpgrade = true
log.Error(err.Error())
}
log.Infof("CRD %s exists as v1, CN[v%s]", crdName, vK8s.String())
if needUpgrade || vNew.GreaterThan(vK8s) {
// Upgrade the CRDl
_, err = clientset.ApiextensionsV1().CustomResourceDefinitions().Update(context.Background(), &crd, metav1.UpdateOptions{})
if err != nil {
return err
}
log.Infof("CRD %s updated", crdName)
log.Infof("CRD %s updated, CN[v%s] -> CN[v%s]", crdName, vK8s.String(), vNew.String())
}
continue
} else {
Expand Down

0 comments on commit 6f6bf4c

Please sign in to comment.