@@ -27,8 +27,10 @@ import (
27
27
"github.com/spf13/cobra"
28
28
appsv1 "k8s.io/api/apps/v1"
29
29
batchv1 "k8s.io/api/batch/v1"
30
+ batchv1beta1 "k8s.io/api/batch/v1beta1"
30
31
corev1 "k8s.io/api/core/v1"
31
32
policyv1 "k8s.io/api/policy/v1"
33
+ policyv1beta1 "k8s.io/api/policy/v1beta1"
32
34
apierrors "k8s.io/apimachinery/pkg/api/errors"
33
35
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
34
36
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
@@ -90,6 +92,17 @@ var namespacedResources = []schema.GroupVersionResource{{
90
92
Resource : "serviceaccounts" ,
91
93
}}
92
94
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
+
93
106
// newSupportCommand returns the support subcommand of the PGO plugin.
94
107
func newSupportExportCommand (config * internal.Config ) * cobra.Command {
95
108
cmd := & cobra.Command {
@@ -388,6 +401,22 @@ func gatherNamespacedAPIResources(ctx context.Context,
388
401
List (ctx , metav1.ListOptions {
389
402
LabelSelector : "postgres-operator.crunchydata.com/cluster=" + clusterName ,
390
403
})
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
+ }
391
420
if err != nil {
392
421
if apierrors .IsForbidden (err ) {
393
422
cmd .Println (err .Error ())
0 commit comments