Skip to content

Commit dd5d2fa

Browse files
Merge pull request #6 from oliveiraxavier/fix/edit-configmap-and-prefix
Edit configmap name and prefix name
2 parents 07b8d3a + 5264b2f commit dd5d2fa

File tree

13 files changed

+113
-57
lines changed

13 files changed

+113
-57
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Image URL to use all building/pushing image targets
2-
APP_VERSION ?=1.0.0
2+
APP_VERSION ?=1.0.1
33
IMG ?= oxmarcos/trashed-resources-controller:${APP_VERSION}
44

55
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ trashedresource name is composed of the "trashed-action + resource type + resour
5454
1 - With curl
5555
5656
```sh
57-
curl https://raw.githubusercontent.com/oliveiraxavier/trashed-resources-k8s-crd/1.0.0/kubectl-trashedresources \
58-
-o ~/.local/bin/kubectl-trashedresources
57+
curl https://raw.githubusercontent.com/oliveiraxavier/trashed-resources-k8s-crd/1.0.0/bin/kubectl-trashedresources \
58+
-O --output-dir ~/.local/bin
5959
```
6060

6161
- Add it to your path if necessary
@@ -79,19 +79,19 @@ echo export PATH=$PATH:$(pwd)/bin >> ~/.zshrc
7979

8080
```sh
8181
# For trashed-resource named trashed-deleted-deployment-nginx-deployment-20260301-230159
82-
kubectl trashedresources prune --name trashed-deleted-deployment-nginx-deployment-20260301-230159
82+
kubectl trashedresources prune --name trashed-deleted-deployment-nginx-deployment-20260301-230159 --namespace default
8383

8484
# For trashed-resource named trashed-deleted-deployment-nginx-deployment-20260301-230159 and age older than 12 minutes
85-
kubectl trashedresources prune --name trashed-deleted-deployment-nginx-deployment-20260301-230159 --older-than 12m
85+
kubectl trashedresources prune --name trashed-deleted-deployment-nginx-deployment-20260301-230159 --older-than 12m --namespace default
8686

8787
# For trashed-resource named trashed-deleted-deployment-nginx-deployment-20260301-230159 and age older than 1 hour
88-
kubectl trashedresources prune --name trashed-deleted-deployment-nginx-deployment-20260301-230159 --older-than 1h
88+
kubectl trashedresources prune --name trashed-deleted-deployment-nginx-deployment-20260301-230159 --older-than 1h --namespace default
8989

9090
# For trashed-resource named trashed-deleted-deployment-nginx-deployment-20260301-230159 and age older than 1 day
91-
kubectl trashedresources prune --name trashed-deleted-deployment-nginx-deployment-20260301-230159 --older-than 1d
91+
kubectl trashedresources prune --name trashed-deleted-deployment-nginx-deployment-20260301-230159 --older-than 1d --namespace default
9292

9393
# For all trashed-resources in the cluster with age older than 1 day
94-
kubectl trashedresources prune --older-than 1d
94+
kubectl trashedresources prune --older-than 1d --namespace default
9595
```
9696

9797
## Getting Started to contribute or test/install from source

cmd/kubectl-trashedresources/main.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,15 +196,26 @@ func restoreResource(c client.Client, name, namespace string) error {
196196
err = c.Create(ctx, restoredObject)
197197
if err != nil {
198198
if errors.IsAlreadyExists(err) {
199-
return fmt.Errorf("resource %s %s/%s already exists", restoredObject.GetKind(), restoredObject.GetNamespace(), restoredObject.GetName())
199+
return fmt.Errorf("resource %s %s/%s already exists",
200+
restoredObject.GetKind(),
201+
restoredObject.GetNamespace(),
202+
restoredObject.GetName(),
203+
)
200204
}
201205
return fmt.Errorf("failed to create restored resource: %v", err)
202206
}
203207

204-
fmt.Printf("Success! Resource %s %s/%s restored.\n", restoredObject.GetKind(), restoredObject.GetNamespace(), restoredObject.GetName())
208+
fmt.Printf("Success! Resource %s %s/%s restored.\n",
209+
restoredObject.GetKind(),
210+
restoredObject.GetNamespace(),
211+
restoredObject.GetName())
205212
err = c.Delete(ctx, trashed, client.PropagationPolicy(metav1.DeletePropagationBackground))
206213
if err != nil {
207-
fmt.Printf("Warning: failed to delete TrashedResource %s/%s: %v. You should manually delete it\n", namespace, name, err)
214+
fmt.Printf("Warning: failed to delete TrashedResource %s/%s: %v. You should manually delete it\n",
215+
namespace,
216+
name,
217+
err,
218+
)
208219
}
209220
return nil
210221
}

config/default/kustomization.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ namespace: trashed-resources-system
66
# "wordpress" becomes "alices-wordpress".
77
# Note that it should also match with the prefix (text before '-') of the namespace
88
# field above.
9+
# If you change this name, change in controller
10+
# cmName = "trashed-resources-config"
911
namePrefix: trashed-resources-
1012

1113
# Labels to add to all resources and selectors.

config/default/metrics_service.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: v1
22
kind: Service
33
metadata:
44
labels:
5-
control-plane: controller-manager
5+
control-plane: trashed-resources-controller-manager
66
app.kubernetes.io/name: trashed-resources
77
app.kubernetes.io/managed-by: kustomize
88
name: controller-manager-metrics-service
@@ -14,5 +14,5 @@ spec:
1414
protocol: TCP
1515
targetPort: 8443
1616
selector:
17-
control-plane: controller-manager
17+
control-plane: trashed-resources-controller-manager
1818
app.kubernetes.io/name: trashed-resources

config/manager/kustomization.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ kind: Kustomization
55
images:
66
- name: controller
77
newName: oxmarcos/trashed-resources-controller
8-
newTag: 1.0.0
8+
newTag: 1.0.1

config/manager/manager.yaml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@ apiVersion: v1
22
kind: Namespace
33
metadata:
44
labels:
5-
control-plane: controller-manager
5+
control-plane: trashed-resources-controller-manager
66
app.kubernetes.io/name: trashed-resources
77
app.kubernetes.io/managed-by: kustomize
88
name: system
99
---
1010
apiVersion: v1
1111
kind: ConfigMap
1212
metadata:
13-
name: trashedresources-config
13+
# After run make build-installer this name will be trashed-resources-config
14+
# because namePrefix: trashed-resources
15+
# If you change this name, change in controller
16+
# cmName = "trashed-resources-config"
17+
name: config
18+
# If you change this namespace, change in code too
1419
namespace: trashed-resources-system
1520
data:
1621
namespacesToIgnore: istio-system; kube-node-lease; kube-public; kube-system
@@ -26,21 +31,21 @@ metadata:
2631
name: controller-manager
2732
namespace: trashed-resources-system
2833
labels:
29-
control-plane: controller-manager
34+
control-plane: trashed-resources-controller-manager
3035
app.kubernetes.io/name: trashed-resources
3136
app.kubernetes.io/managed-by: kustomize
3237
spec:
3338
selector:
3439
matchLabels:
35-
control-plane: controller-manager
40+
control-plane: trashed-resources-controller-manager
3641
app.kubernetes.io/name: trashed-resources
3742
replicas: 1
3843
template:
3944
metadata:
4045
annotations:
4146
kubectl.kubernetes.io/default-container: manager
4247
labels:
43-
control-plane: controller-manager
48+
control-plane: trashed-resources-controller-manager
4449
app.kubernetes.io/name: trashed-resources
4550
spec:
4651
# TODO(user): Uncomment the following code to configure the nodeAffinity expression
@@ -76,8 +81,14 @@ spec:
7681
args:
7782
- --leader-elect
7883
- --health-probe-bind-address=:8081
84+
envFrom:
85+
- configMapRef:
86+
name: trashed-resources-config
7987
image: controller:latest
88+
imagePullPolicy: IfNotPresent
8089
name: manager
90+
stdin: true
91+
tty: true
8192
ports: []
8293
securityContext:
8394
allowPrivilegeEscalation: false

config/network-policy/allow-metrics-traffic.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ metadata:
1212
spec:
1313
podSelector:
1414
matchLabels:
15-
control-plane: controller-manager
15+
control-plane: trashed-resources-controller-manager
1616
app.kubernetes.io/name: trashed-resources
1717
policyTypes:
1818
- Ingress

config/prometheus/monitor.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apiVersion: monitoring.coreos.com/v1
33
kind: ServiceMonitor
44
metadata:
55
labels:
6-
control-plane: controller-manager
6+
control-plane: trashed-resources-controller-manager
77
app.kubernetes.io/name: trashed-resources
88
app.kubernetes.io/managed-by: kustomize
99
name: controller-manager-metrics-monitor
@@ -23,5 +23,5 @@ spec:
2323
insecureSkipVerify: true
2424
selector:
2525
matchLabels:
26-
control-plane: controller-manager
26+
control-plane: trashed-resources-controller-manager
2727
app.kubernetes.io/name: trashed-resources

dist/install.yaml

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ metadata:
44
labels:
55
app.kubernetes.io/managed-by: kustomize
66
app.kubernetes.io/name: trashed-resources
7-
control-plane: controller-manager
7+
control-plane: trashed-resources-controller-manager
88
name: trashed-resources-system
99
---
1010
apiVersion: apiextensions.k8s.io/v1
@@ -320,7 +320,7 @@ data:
320320
namespacesToIgnore: istio-system; kube-node-lease; kube-public; kube-system
321321
kind: ConfigMap
322322
metadata:
323-
name: trashed-resources-trashedresources-config
323+
name: trashed-resources-config
324324
namespace: trashed-resources-system
325325
---
326326
apiVersion: v1
@@ -329,7 +329,7 @@ metadata:
329329
labels:
330330
app.kubernetes.io/managed-by: kustomize
331331
app.kubernetes.io/name: trashed-resources
332-
control-plane: controller-manager
332+
control-plane: trashed-resources-controller-manager
333333
name: trashed-resources-controller-manager-metrics-service
334334
namespace: trashed-resources-system
335335
spec:
@@ -340,30 +340,30 @@ spec:
340340
targetPort: 8443
341341
selector:
342342
app.kubernetes.io/name: trashed-resources
343-
control-plane: controller-manager
343+
control-plane: trashed-resources-controller-manager
344344
---
345345
apiVersion: apps/v1
346346
kind: Deployment
347347
metadata:
348348
labels:
349349
app.kubernetes.io/managed-by: kustomize
350350
app.kubernetes.io/name: trashed-resources
351-
control-plane: controller-manager
351+
control-plane: trashed-resources-controller-manager
352352
name: trashed-resources-controller-manager
353353
namespace: trashed-resources-system
354354
spec:
355355
replicas: 1
356356
selector:
357357
matchLabels:
358358
app.kubernetes.io/name: trashed-resources
359-
control-plane: controller-manager
359+
control-plane: trashed-resources-controller-manager
360360
template:
361361
metadata:
362362
annotations:
363363
kubectl.kubernetes.io/default-container: manager
364364
labels:
365365
app.kubernetes.io/name: trashed-resources
366-
control-plane: controller-manager
366+
control-plane: trashed-resources-controller-manager
367367
spec:
368368
containers:
369369
- args:
@@ -372,7 +372,11 @@ spec:
372372
- --health-probe-bind-address=:8081
373373
command:
374374
- /manager
375-
image: oxmarcos/trashed-resources-controller:1.0.0
375+
envFrom:
376+
- configMapRef:
377+
name: trashed-resources-config
378+
image: oxmarcos/trashed-resources-controller:1.0.1
379+
imagePullPolicy: IfNotPresent
376380
livenessProbe:
377381
httpGet:
378382
path: /healthz
@@ -399,6 +403,8 @@ spec:
399403
capabilities:
400404
drop:
401405
- ALL
406+
stdin: true
407+
tty: true
402408
volumeMounts: []
403409
securityContext:
404410
runAsNonRoot: true

0 commit comments

Comments
 (0)