Add cr version check for PMM
package v1
import (
+ "encoding/json"
"fmt"
+ "strings"
+ v "github.com/hashicorp/go-version"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -370,9 +373,35 @@ func (cr *PerconaXtraDBCluster) CheckNSetDefaults() (changed bool, err error) {
}
}
+ if !cr.acceptableVersionForPMM() {
+ cr.Spec.PMM = nil
+ }
+
return changed, nil
}
+func (cr *PerconaXtraDBCluster) acceptableVersionForPMM() bool {
+ apiVersion := cr.APIVersion
+ if lastCR, ok := cr.Annotations["kubectl.kubernetes.io/last-applied-configuration"]; ok {
+ var newCR PerconaXtraDBCluster
+ err := json.Unmarshal([]byte(lastCR), &newCR)
+ if err != nil {
+ return false
+ }
+ apiVersion = newCR.APIVersion
+ }
+ crVersion := strings.Replace(strings.TrimLeft(apiVersion, "pxc.percona.com/v"), "-", ".", -1)
+ checkVersion, err := v.NewVersion("1.2.0")
+ if err != nil {
+ return false
+ }
+ currentVersion, err := v.NewVersion(crVersion)
+ if err != nil {
+ return false
+ }
+ return currentVersion.GreaterThanOrEqual(checkVersion)
+}
+
const AffinityTopologyKeyOff = "none"
var affinityValidTopologyKeys = map[string]struct{}{
