Skip to content

Commit 1024184

Browse files
committed
Add support export collection of LimitRanges and Ingresses
With this update, the support export command collects any LimitRanges or Ingresses if defined in the PostgresCluster's Namespace. Issue: [sc-18056] Issue: [sc-18061]
1 parent 65c1660 commit 1024184

File tree

9 files changed

+261
-9
lines changed

9 files changed

+261
-9
lines changed

docs/content/reference/pgo_support_export.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ PostgresCluster.
1818
deployments.apps [list]
1919
endpoints [list]
2020
events [get list]
21+
ingresses.networking.k8s.io [list]
2122
jobs.batch [list]
23+
limitranges [list]
2224
namespaces [get]
2325
nodes [list]
2426
persistentvolumeclaims [list]

internal/cmd/export.go

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
batchv1 "k8s.io/api/batch/v1"
3232
batchv1beta1 "k8s.io/api/batch/v1beta1"
3333
corev1 "k8s.io/api/core/v1"
34+
networkingv1 "k8s.io/api/networking/v1"
3435
policyv1 "k8s.io/api/policy/v1"
3536
policyv1beta1 "k8s.io/api/policy/v1beta1"
3637
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -65,7 +66,8 @@ or attach as a email reply to your existing Support Ticket` + "\n"
6566
Please request file share link by emailing [email protected]` + "\n"
6667
)
6768

68-
var namespacedResources = []schema.GroupVersionResource{{
69+
// namespaced resources that have a cluster Label
70+
var clusterNamespacedResources = []schema.GroupVersionResource{{
6971
Group: appsv1.SchemeGroupVersion.Group,
7072
Version: appsv1.SchemeGroupVersion.Version,
7173
Resource: "statefulsets",
@@ -126,6 +128,17 @@ var removedNamespacedResources = []schema.GroupVersionResource{{
126128
Resource: "poddisruptionbudgets",
127129
}}
128130

131+
// namespaced resources that impact PGO created objects in the namespace
132+
var otherNamespacedResources = []schema.GroupVersionResource{{
133+
Group: networkingv1.SchemeGroupVersion.Group,
134+
Version: networkingv1.SchemeGroupVersion.Version,
135+
Resource: "ingresses",
136+
}, {
137+
Group: corev1.SchemeGroupVersion.Group,
138+
Version: corev1.SchemeGroupVersion.Version,
139+
Resource: "limitranges",
140+
}}
141+
129142
// newSupportCommand returns the support subcommand of the PGO plugin.
130143
func newSupportExportCommand(config *internal.Config) *cobra.Command {
131144
cmd := &cobra.Command{
@@ -142,7 +155,9 @@ PostgresCluster.
142155
deployments.apps [list]
143156
endpoints [list]
144157
events [get list]
158+
ingresses.networking.k8s.io [list]
145159
jobs.batch [list]
160+
limitranges [list]
146161
namespaces [get]
147162
nodes [list]
148163
persistentvolumeclaims [list]
@@ -300,7 +315,20 @@ kubectl pgo support export daisy --monitoring-namespace another-namespace --outp
300315

301316
// TODO (jmckulk): pod describe output
302317
if err == nil {
303-
err = gatherNamespacedAPIResources(ctx, dynamicClient, namespace, clusterName, tw, cmd)
318+
// get Namespaced resources that have cluster label
319+
nsListOpts := metav1.ListOptions{
320+
LabelSelector: "postgres-operator.crunchydata.com/cluster=" + clusterName,
321+
}
322+
err = gatherNamespacedAPIResources(ctx, dynamicClient, namespace,
323+
clusterName, clusterNamespacedResources, nsListOpts, tw, cmd)
324+
}
325+
326+
if err == nil {
327+
// get other Namespaced resources that do not have the cluster label
328+
// but may otherwise impact the PostgresCluster's operation
329+
otherListOpts := metav1.ListOptions{}
330+
err = gatherNamespacedAPIResources(ctx, dynamicClient, namespace,
331+
clusterName, otherNamespacedResources, otherListOpts, tw, cmd)
304332
}
305333

306334
if err == nil {
@@ -556,14 +584,13 @@ func gatherNamespacedAPIResources(ctx context.Context,
556584
client dynamic.Interface,
557585
namespace string,
558586
clusterName string,
587+
namespacedResources []schema.GroupVersionResource,
588+
listOpts metav1.ListOptions,
559589
tw *tar.Writer,
560590
cmd *cobra.Command,
561591
) error {
562592
for _, gvr := range namespacedResources {
563-
list, err := client.Resource(gvr).Namespace(namespace).
564-
List(ctx, metav1.ListOptions{
565-
LabelSelector: "postgres-operator.crunchydata.com/cluster=" + clusterName,
566-
})
593+
list, err := client.Resource(gvr).Namespace(namespace).List(ctx, listOpts)
567594
// If the API returns an IsNotFound error, it is likely because the kube version in use
568595
// doesn't support the version of the resource we are attempting to use and there is an
569596
// earlier version we can use. This block will check the "removed" resources for a match
@@ -573,9 +600,7 @@ func gatherNamespacedAPIResources(ctx context.Context,
573600
if bgvr.Resource == gvr.Resource {
574601
gvr = bgvr
575602
list, err = client.Resource(gvr).Namespace(namespace).
576-
List(ctx, metav1.ListOptions{
577-
LabelSelector: "postgres-operator.crunchydata.com/cluster=" + clusterName,
578-
})
603+
List(ctx, listOpts)
579604
break
580605
}
581606
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apiVersion: kuttl.dev/v1beta1
2+
kind: TestStep
3+
delete:
4+
- apiVersion: postgres-operator.crunchydata.com/v1beta1
5+
kind: PostgresCluster
6+
name: kuttl-support-cluster
7+
- apiVersion: postgres-operator.crunchydata.com/v1beta1
8+
kind: PostgresCluster
9+
name: kuttl-support-monitoring-cluster
10+
- apiVersion: apps/v1
11+
kind: Deployment
12+
name: crunchy-prometheus
13+
- apiVersion: apps/v1
14+
kind: Deployment
15+
name: crunchy-grafana
16+
- apiVersion: apps/v1
17+
kind: Deployment
18+
name: crunchy-alertmanager
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
apiVersion: postgres-operator.crunchydata.com/v1beta1
3+
kind: PostgresCluster
4+
metadata:
5+
name: kuttl-support-cluster
6+
---
7+
apiVersion: postgres-operator.crunchydata.com/v1beta1
8+
kind: PostgresCluster
9+
metadata:
10+
name: kuttl-support-monitoring-cluster
11+
---
12+
apiVersion: apps/v1
13+
kind: Deployment
14+
metadata:
15+
name: crunchy-prometheus
16+
---
17+
apiVersion: apps/v1
18+
kind: Deployment
19+
metadata:
20+
name: crunchy-grafana
21+
---
22+
apiVersion: apps/v1
23+
kind: Deployment
24+
metadata:
25+
name: crunchy-alertmanager
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# create a PostgresCluster
2+
apiVersion: postgres-operator.crunchydata.com/v1beta1
3+
kind: PostgresCluster
4+
metadata:
5+
name: kuttl-support-cluster-other
6+
spec:
7+
postgresVersion: 14
8+
instances:
9+
- dataVolumeClaimSpec:
10+
accessModes: [ReadWriteOnce]
11+
resources: { requests: { storage: 1Gi } }
12+
backups:
13+
pgbackrest:
14+
repos:
15+
- name: repo1
16+
volume:
17+
volumeClaimSpec:
18+
accessModes: [ReadWriteOnce]
19+
resources: { requests: { storage: 1Gi } }
20+
monitoring:
21+
pgmonitor:
22+
exporter: {}
23+
---
24+
# create a LimitRange
25+
apiVersion: v1
26+
kind: LimitRange
27+
metadata:
28+
name: storagelimits
29+
spec:
30+
limits:
31+
- type: PersistentVolumeClaim
32+
max:
33+
storage: 2Gi
34+
min:
35+
storage: 500Mi
36+
37+
---
38+
# create an Ingress
39+
apiVersion: networking.k8s.io/v1
40+
kind: Ingress
41+
metadata:
42+
name: minimal-test-ingress
43+
annotations:
44+
nginx.ingress.kubernetes.io/rewrite-target: /
45+
spec:
46+
ingressClassName: simple-example
47+
rules:
48+
- http:
49+
paths:
50+
- path: /testpath
51+
pathType: Prefix
52+
backend:
53+
service:
54+
name: test
55+
port:
56+
number: 80
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
apiVersion: postgres-operator.crunchydata.com/v1beta1
2+
kind: PostgresCluster
3+
metadata:
4+
name: kuttl-support-cluster-other
5+
spec:
6+
backups:
7+
pgbackrest:
8+
repos:
9+
- name: repo1
10+
volume:
11+
volumeClaimSpec:
12+
accessModes:
13+
- "ReadWriteOnce"
14+
resources:
15+
requests:
16+
storage: 1Gi
17+
instances:
18+
- dataVolumeClaimSpec:
19+
accessModes:
20+
- "ReadWriteOnce"
21+
resources:
22+
requests:
23+
storage: 1Gi
24+
replicas: 1
25+
postgresVersion: 14
26+
status:
27+
instances:
28+
- name: "00"
29+
readyReplicas: 1
30+
replicas: 1
31+
updatedReplicas: 1
32+
---
33+
apiVersion: v1
34+
kind: LimitRange
35+
metadata:
36+
name: storagelimits
37+
---
38+
apiVersion: networking.k8s.io/v1
39+
kind: Ingress
40+
metadata:
41+
name: minimal-test-ingress
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
apiVersion: kuttl.dev/v1beta1
3+
kind: TestStep
4+
commands:
5+
- script: kubectl-pgo --namespace $NAMESPACE support export kuttl-support-cluster-other -o .
6+
- script: tar -xf ./crunchy_k8s_support_export_*.tar.gz
7+
- script: |
8+
#! /bin/bash
9+
10+
CLEANUP="rm -r ./kuttl-support-cluster-other ./crunchy_k8s_support_export_*.tar.gz"
11+
12+
# LimitRange directory and list file path
13+
LR_DIR="./kuttl-support-cluster-other/limitranges/"
14+
LR_LIST="${LR_DIR}list"
15+
16+
# check for limitrange object name
17+
LRO=$(awk 'NR==2 {print $1}' "${LR_LIST}")
18+
[[ "${LRO}" == 'storagelimits' ]] || {
19+
echo "Expected 'storagelimits' limitrange, got:"
20+
echo "${LRO}"
21+
eval "$CLEANUP"
22+
exit 1
23+
}
24+
25+
# check for a .yaml file for the limitrange object
26+
LR_FILE="${LR_DIR}storagelimits.yaml"
27+
if [ ! -f ${LR_FILE} ]
28+
then
29+
echo "Expected directory with file, ${LR_FILE}, got:"
30+
ls ${LR_DIR}
31+
eval "$CLEANUP"
32+
exit 1
33+
fi
34+
35+
# Ingress directory and list file path
36+
I_DIR="./kuttl-support-cluster-other/ingresses/"
37+
I_LIST="${I_DIR}list"
38+
39+
# check for ingress object name
40+
IO=$(awk 'NR==2 {print $1}' ${I_LIST})
41+
[[ "${IO}" == 'minimal-test-ingress' ]] || {
42+
echo "Expected 'minimal-test-ingress' ingress, got:"
43+
echo "${IO}"
44+
eval "$CLEANUP"
45+
exit 1
46+
}
47+
48+
# check for a .yaml file for the ingress object
49+
I_FILE="${I_DIR}minimal-test-ingress.yaml"
50+
if [ ! -f ${I_FILE} ]
51+
then
52+
echo "Expected directory with file, ${I_FILE}, got:"
53+
ls ${I_DIR}
54+
eval "$CLEANUP"
55+
exit 1
56+
fi
57+
58+
- script: rm -r ./kuttl-support-cluster-other ./crunchy_k8s_support_export_*.tar.gz
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: kuttl.dev/v1beta1
2+
kind: TestStep
3+
delete:
4+
- apiVersion: postgres-operator.crunchydata.com/v1beta1
5+
kind: PostgresCluster
6+
name: kuttl-support-cluster-other
7+
- apiVersion: v1
8+
kind: LimitRange
9+
name: storagelimits
10+
- apiVersion: networking.k8s.io/v1
11+
kind: Ingress
12+
name: minimal-test-ingress
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
apiVersion: postgres-operator.crunchydata.com/v1beta1
3+
kind: PostgresCluster
4+
metadata:
5+
name: kuttl-support-cluster-other
6+
---
7+
apiVersion: v1
8+
kind: LimitRange
9+
metadata:
10+
name: storagelimits
11+
---
12+
apiVersion: networking.k8s.io/v1
13+
kind: Ingress
14+
metadata:
15+
name: minimal-test-ingress

0 commit comments

Comments
 (0)