@@ -27,8 +27,10 @@ import (
2727 "github.com/spf13/cobra"
2828 appsv1 "k8s.io/api/apps/v1"
2929 batchv1 "k8s.io/api/batch/v1"
30+ batchv1beta1 "k8s.io/api/batch/v1beta1"
3031 corev1 "k8s.io/api/core/v1"
3132 policyv1 "k8s.io/api/policy/v1"
33+ policyv1beta1 "k8s.io/api/policy/v1beta1"
3234 apierrors "k8s.io/apimachinery/pkg/api/errors"
3335 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3436 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
@@ -90,6 +92,17 @@ var namespacedResources = []schema.GroupVersionResource{{
9092 Resource : "serviceaccounts" ,
9193}}
9294
95+ // These "removed" GVRs are for making our CLI backwards compatible with older PGO versions.
96+ var removedNamespacedResources = []schema.GroupVersionResource {{
97+ Group : batchv1beta1 .SchemeGroupVersion .Group ,
98+ Version : batchv1beta1 .SchemeGroupVersion .Version ,
99+ Resource : "cronjobs" ,
100+ }, {
101+ Group : policyv1beta1 .SchemeGroupVersion .Group ,
102+ Version : policyv1beta1 .SchemeGroupVersion .Version ,
103+ Resource : "poddisruptionbudgets" ,
104+ }}
105+
93106// newSupportCommand returns the support subcommand of the PGO plugin.
94107func newSupportExportCommand (config * internal.Config ) * cobra.Command {
95108 cmd := & cobra.Command {
@@ -388,6 +401,22 @@ func gatherNamespacedAPIResources(ctx context.Context,
388401 List (ctx , metav1.ListOptions {
389402 LabelSelector : "postgres-operator.crunchydata.com/cluster=" + clusterName ,
390403 })
404+ // If the API returns an IsNotFound error, it is likely because the kube version in use
405+ // doesn't support the version of the resource we are attempting to use and there is an
406+ // earlier version we can use. This block will check the "removed" resources for a match
407+ // and use it if it exists.
408+ if apierrors .IsNotFound (err ) {
409+ for _ , bgvr := range removedNamespacedResources {
410+ if bgvr .Resource == gvr .Resource {
411+ gvr = bgvr
412+ list , err = client .Resource (gvr ).Namespace (namespace ).
413+ List (ctx , metav1.ListOptions {
414+ LabelSelector : "postgres-operator.crunchydata.com/cluster=" + clusterName ,
415+ })
416+ break
417+ }
418+ }
419+ }
391420 if err != nil {
392421 if apierrors .IsForbidden (err ) {
393422 cmd .Println (err .Error ())
0 commit comments