/
routes-workload.go
3258 lines (2983 loc) · 123 KB
/
routes-workload.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package operator
import (
"context"
"fmt"
"io"
"net/http"
"strconv"
"strings"
"github.com/mogenius/punq/services"
"github.com/mogenius/punq/utils"
v1Cert "github.com/cert-manager/cert-manager/pkg/apis/acme/v1"
cmapi "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
v6Snap "github.com/kubernetes-csi/external-snapshotter/client/v6/apis/volumesnapshot/v1"
"github.com/mogenius/punq/dtos"
"github.com/mogenius/punq/kubernetes"
v1Apps "k8s.io/api/apps/v1"
v2Scale "k8s.io/api/autoscaling/v2"
v1Job "k8s.io/api/batch/v1"
v1Coordination "k8s.io/api/coordination/v1"
v1 "k8s.io/api/core/v1"
v1Networking "k8s.io/api/networking/v1"
v1Rbac "k8s.io/api/rbac/v1"
v1Scheduling "k8s.io/api/scheduling/v1"
v1Storage "k8s.io/api/storage/v1"
apiExt "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
)
func InitWorkloadRoutes(router *gin.Engine) {
workloadRoutes := router.Group("/workload")
{
workloadRoutes.GET("/templates", Auth(dtos.READER), allWorkloadTemplates)
workloadRoutes.GET("/available-resources", Auth(dtos.READER), allKubernetesResources)
// namespace
namespaceWorkloadRoutes := workloadRoutes.Group(fmt.Sprintf("/%s", strings.ToLower(kubernetes.RES_NAMESPACE)), Auth(dtos.USER), RequireContextId())
{
namespaceWorkloadRoutes.GET("/", allNamespaces) // PARAM: -
namespaceWorkloadRoutes.GET("/describe/:name", validateParam("name"), describeNamespaces) // PARAM: name
namespaceWorkloadRoutes.DELETE("/:name", Auth(dtos.ADMIN), validateParam("name"), deleteNamespace) // PARAM: name
namespaceWorkloadRoutes.PATCH("/", patchNamespace) // BODY: json-object
namespaceWorkloadRoutes.POST("/", createNamespace) // BODY: yaml-object
}
// pod
podWorkloadRoutes := workloadRoutes.Group(fmt.Sprintf("/%s", strings.ToLower(kubernetes.RES_POD)), Auth(dtos.USER), RequireContextId())
{
podWorkloadRoutes.GET("/", allPods)
podWorkloadRoutes.GET("/describe/:namespace/:name", validateParam("namespace", "name"), describePod) // PARAM: namespace
podWorkloadRoutes.GET("/logs/:namespace/:name", validateParam("namespace", "name"), logsPod) // PARAM: namespace
podWorkloadRoutes.DELETE("/:namespace/:name", validateParam("namespace", "name"), deletePod) // PARAM: namespace, name
podWorkloadRoutes.PATCH("/", patchPod) // BODY: json-object
podWorkloadRoutes.POST("/", createPod) // BODY: yaml-object
}
// deployment
deploymentWorkloadRoutes := workloadRoutes.Group(fmt.Sprintf("/%s", strings.ToLower(kubernetes.RES_DEPLOYMENT)), Auth(dtos.USER), RequireContextId())
{
deploymentWorkloadRoutes.GET("/", allDeployments) // PARAM: namespace
deploymentWorkloadRoutes.GET("/describe/:namespace/:name", validateParam("namespace", "name"), describeDeployment) // PARAM: namespace, name
deploymentWorkloadRoutes.DELETE("/:namespace/:name", validateParam("namespace", "name"), deleteDeployment) // PARAM: namespace, name
deploymentWorkloadRoutes.PATCH("/", patchDeployment) // BODY: json-object
deploymentWorkloadRoutes.POST("/´", createDeployment) // BODY: yaml-object
}
// service
serviceWorkloadRoutes := workloadRoutes.Group(fmt.Sprintf("/%s", strings.ToLower(kubernetes.RES_SERVICE)), Auth(dtos.USER), RequireContextId())
{
serviceWorkloadRoutes.GET("/", allServices) // PARAM: namespace
serviceWorkloadRoutes.GET("/describe/:namespace/:name", validateParam("namespace", "name"), describeService) // PARAM: namespace, name
serviceWorkloadRoutes.DELETE("/:namespace/:name", validateParam("namespace", "name"), deleteService) // PARAM: namespace, name
serviceWorkloadRoutes.PATCH("/", patchService) // BODY: json-object
serviceWorkloadRoutes.POST("/", createService) // BODY: yaml-object
}
// ingress
ingressWorkloadRoutes := workloadRoutes.Group(fmt.Sprintf("/%s", strings.ToLower(kubernetes.RES_INGRESS)), Auth(dtos.USER), RequireContextId())
{
ingressWorkloadRoutes.GET("/", allIngresses) // PARAM: namespace
ingressWorkloadRoutes.GET("/describe/:namespace/:name", validateParam("namespace", "name"), describeIngress) // PARAM: namespace, name
ingressWorkloadRoutes.DELETE("/:namespace/:name", validateParam("namespace", "name"), deleteIngress) // PARAM: json-object
ingressWorkloadRoutes.PATCH("/", patchIngress) // BODY: json-object
ingressWorkloadRoutes.POST("/", createIngress) // BODY: yaml-object
}
// configmap
configmapWorkloadRoutes := workloadRoutes.Group(fmt.Sprintf("/%s", strings.ToLower(kubernetes.RES_CONFIG_MAP)), Auth(dtos.USER), RequireContextId())
{
configmapWorkloadRoutes.GET("/", allConfigmaps) // PARAM: namespace
configmapWorkloadRoutes.GET("/describe/:namespace/:name", validateParam("namespace", "name"), describeConfigmap) // PARAM: namespace, name
configmapWorkloadRoutes.DELETE("/:namespace/:name", validateParam("namespace", "name"), deleteConfigmap) // PARAM: namespace, name
configmapWorkloadRoutes.PATCH("/", patchConfigmap) // BODY: json-object
workloadRoutes.POST("/´", createConfigmap) // BODY: yaml-object
}
// secret
secretWorkloadRoutes := workloadRoutes.Group(fmt.Sprintf("/%s", strings.ToLower(kubernetes.RES_SECRET)), Auth(dtos.ADMIN), RequireContextId())
{
secretWorkloadRoutes.GET("/", allSecrets) // PARAM: namespace
secretWorkloadRoutes.GET("/describe/:namespace/:name", validateParam("namespace", "name"), describeSecret) // PARAM: namespace, name
secretWorkloadRoutes.DELETE("/:namespace/:name", validateParam("namespace", "name"), deleteSecret) // PARAM: namespace, name
secretWorkloadRoutes.PATCH("/", patchSecret) // BODY: json-object
secretWorkloadRoutes.POST("/", createSecret) // BODY: yaml-object
}
// node
nodeWorkloadRoutes := workloadRoutes.Group(fmt.Sprintf("/%s", strings.ToLower(kubernetes.RES_NODE)), Auth(dtos.USER), RequireContextId())
{
nodeWorkloadRoutes.GET("/", allNodes) // -
nodeWorkloadRoutes.GET("/describe/:name", validateParam("name"), describeNode) // PARAM: namespace
}
// daemon-set
daemonSetWorkloadRoutes := workloadRoutes.Group(fmt.Sprintf("/%s", strings.ToLower(kubernetes.RES_DAEMON_SET)), Auth(dtos.USER), RequireContextId())
{
daemonSetWorkloadRoutes.GET("/", allDaemonSets) // PARAM: namespace
daemonSetWorkloadRoutes.GET("/describe/:namespace/:name", validateParam("namespace", "name"), describeDaemonSet) // PARAM: namespace, name
daemonSetWorkloadRoutes.DELETE("/:namespace/:name", validateParam("namespace", "name"), deleteDaemonSet) // PARAM: namespace, name
daemonSetWorkloadRoutes.PATCH("/", patchDaemonSet) // BODY: json-object
daemonSetWorkloadRoutes.POST("/", createDaemonSet) // BODY: yaml-object
}
// stateful-set
statefulSetWorkloadRoutes := workloadRoutes.Group(fmt.Sprintf("/%s", strings.ToLower(kubernetes.RES_STATEFUL_SET)), Auth(dtos.USER), RequireContextId())
{
statefulSetWorkloadRoutes.GET("/", allStatefulSets) // PARAM: namespace
statefulSetWorkloadRoutes.GET("/describe/:namespace/:name", validateParam("namespace", "name"), describeStatefulSet) // PARAM: namespace, name
statefulSetWorkloadRoutes.DELETE("/:namespace/:name", validateParam("namespace", "name"), deleteStatefulSet) // PARAM: namespace, name
statefulSetWorkloadRoutes.PATCH("/", patchStatefulSet) // BODY: json-object
statefulSetWorkloadRoutes.POST("/", createStatefulSet) // BODY: yaml-object
}
// job
jobWorkloadRoutes := workloadRoutes.Group(fmt.Sprintf("/%s", strings.ToLower(kubernetes.RES_JOB)), Auth(dtos.USER), RequireContextId())
{
jobWorkloadRoutes.GET("/", allJobs) // PARAM: namespace
jobWorkloadRoutes.GET("/describe/:namespace/:name", validateParam("namespace", "name"), describeJob) // PARAM: namespace, name
jobWorkloadRoutes.DELETE("/:namespace/:name", validateParam("namespace", "name"), deleteJob) // PARAM: namespace, name
jobWorkloadRoutes.PATCH("/", patchJob) // BODY: json-object
jobWorkloadRoutes.POST("/", createJob) // BODY: yaml-object
}
// cron-job
cronJobWorkloadRoutes := workloadRoutes.Group(fmt.Sprintf("/%s", strings.ToLower(kubernetes.RES_CRON_JOB)), Auth(dtos.USER), RequireContextId())
{
cronJobWorkloadRoutes.GET("/", allCronJobs) // PARAM: namespace
cronJobWorkloadRoutes.GET("/describe/:namespace/:name", validateParam("namespace", "name"), describeCronJob) // PARAM: namespace, name
cronJobWorkloadRoutes.DELETE("/:namespace/:name", validateParam("namespace", "name"), deleteCronJob) // PARAM: namespace, name
cronJobWorkloadRoutes.PATCH("/", patchCronJob) // BODY: json-object
cronJobWorkloadRoutes.POST("/", createCronJob) // BODY: yaml-object
}
// replicaset
replicaSetWorkloadRoutes := workloadRoutes.Group(fmt.Sprintf("/%s", strings.ToLower(kubernetes.RES_REPLICA_SET)), Auth(dtos.USER), RequireContextId())
{
replicaSetWorkloadRoutes.GET("/", allReplicasets) // PARAM: namespace
replicaSetWorkloadRoutes.GET("/describe/:namespace/:name", validateParam("namespace", "name"), describeReplicaset) // PARAM: namespace, name
replicaSetWorkloadRoutes.DELETE("/:namespace/:name", validateParam("namespace", "name"), deleteReplicaset) // PARAM: namespace, name
replicaSetWorkloadRoutes.PATCH("(", patchReplicaset) // BODY: json-object
replicaSetWorkloadRoutes.POST("/", createReplicaset) // BODY: yaml-object
}
// persistent-volume
persistentVolumeWorkloadRoutes := workloadRoutes.Group(fmt.Sprintf("/%s", strings.ToLower(kubernetes.RES_PERSISTENT_VOLUME)), Auth(dtos.ADMIN), RequireContextId())
{
persistentVolumeWorkloadRoutes.GET("/", allPersistentVolumes) // PARAM: -
persistentVolumeWorkloadRoutes.GET("/describe/:name", validateParam("name"), describePersistentVolume) // PARAM: name
persistentVolumeWorkloadRoutes.DELETE("/:name", validateParam("name"), deletePersistentVolume) // PARAM: name
persistentVolumeWorkloadRoutes.PATCH("/", patchPersistentVolume) // BODY: json-object
persistentVolumeWorkloadRoutes.POST("/", createPersistentVolume) // BODY: yaml-object
}
// persistent-volume-claim
persistentVolumeClaimWorkloadRoutes := workloadRoutes.Group(fmt.Sprintf("/%s", strings.ToLower(kubernetes.RES_PERSISTENT_VOLUME_CLAIM)), RequireContextId())
{
persistentVolumeClaimWorkloadRoutes.GET("/", Auth(dtos.USER), allPersistentVolumeClaims) // PARAM: namespace
persistentVolumeClaimWorkloadRoutes.GET("/describe/:namespace/:name", Auth(dtos.USER), validateParam("namespace", "name"), describePersistentVolumeClaim) // PARAM: namespace, name
persistentVolumeClaimWorkloadRoutes.DELETE("/:namespace/:name", Auth(dtos.ADMIN), validateParam("namespace", "name"), deletePersistentVolumeClaim) // PARAM: namespace, name
persistentVolumeClaimWorkloadRoutes.PATCH("/", Auth(dtos.ADMIN), patchPersistentVolumeClaim) // BODY: json-object
persistentVolumeClaimWorkloadRoutes.POST("/", Auth(dtos.ADMIN), createPersistentVolumeClaim) // BODY: yaml-object
}
// horizontal-pod-autoscaler
horizontalPodAutoscalerWorkloadRoutes := workloadRoutes.Group(fmt.Sprintf("/%s", strings.ToLower(kubernetes.RES_HORIZONTAL_POD_AUTOSCALER)), RequireContextId())
{
horizontalPodAutoscalerWorkloadRoutes.GET("/", Auth(dtos.USER), allHpas) // PARAM: namespace
horizontalPodAutoscalerWorkloadRoutes.GET("/describe/:namespace/:name", Auth(dtos.USER), validateParam("namespace", "name"), describeHpa) // PARAM: namespace, name
horizontalPodAutoscalerWorkloadRoutes.DELETE("/:namespace/:name", Auth(dtos.ADMIN), validateParam("namespace", "name"), deleteHpa) // PARAM: namespace, name
horizontalPodAutoscalerWorkloadRoutes.PATCH("/", Auth(dtos.ADMIN), patchHpa) // BODY: json-object
horizontalPodAutoscalerWorkloadRoutes.POST("/", Auth(dtos.ADMIN), createHpa) // BODY: yaml-object
}
// event
eventWorkloadRoutes := workloadRoutes.Group(fmt.Sprintf("/%s", strings.ToLower(kubernetes.RES_EVENT)), Auth(dtos.USER), RequireContextId())
{
eventWorkloadRoutes.GET("/", allEvents) // PARAM: namespace
eventWorkloadRoutes.GET("/describe/:namespace/:name", validateParam("namespace", "name"), describeEvent) // PARAM: namespace, name
}
// certificate
certificateWorkloadRoutes := workloadRoutes.Group(fmt.Sprintf("/%s", strings.ToLower(kubernetes.RES_CERTIFICATE)), Auth(dtos.USER), RequireContextId())
{
certificateWorkloadRoutes.GET("/", allCertificates) // PARAM: namespace
certificateWorkloadRoutes.GET("/describe/:namespace/:name", validateParam("namespace", "name"), describeCertificate) // PARAM: namespace, name
certificateWorkloadRoutes.DELETE("/:namespace/:name", validateParam("namespace", "name"), deleteCertificate) // PARAM: namespace, name
certificateWorkloadRoutes.PATCH("/", patchCertificate) // BODY: json-object
certificateWorkloadRoutes.POST("/", createCertificate) // BODY: yaml-object
}
// certificate-request
certificateRequestWorkloadRoutes := workloadRoutes.Group(fmt.Sprintf("/%s", strings.ToLower(kubernetes.RES_CERTIFICATE_REQUEST)), Auth(dtos.USER), RequireContextId())
{
certificateRequestWorkloadRoutes.GET("/", allCertificateRequests) // PARAM: namespace
certificateRequestWorkloadRoutes.GET("/describe/:namespace/:name", validateParam("namespace", "name"), describeCertificateRequest) // PARAM: namespace, name
certificateRequestWorkloadRoutes.DELETE("/:namespace/:name", validateParam("namespace", "name"), deleteCertificateRequest) // PARAM: namespace, name
certificateRequestWorkloadRoutes.PATCH("/", patchCertificateRequest) // BODY: json-object
certificateRequestWorkloadRoutes.POST("/", createCertificateRequest) // BODY: yaml-object
}
// orders
ordersWorkloadRoutes := workloadRoutes.Group(fmt.Sprintf("/%s", strings.ToLower(kubernetes.RES_ORDER)), Auth(dtos.USER), RequireContextId())
{
ordersWorkloadRoutes.GET("/", allOrders) // PARAM: namespace
ordersWorkloadRoutes.GET("/describe/:namespace/:name", validateParam("namespace", "name"), describeOrder) // PARAM: namespace, name
ordersWorkloadRoutes.DELETE("/:namespace/:name", validateParam("namespace", "name"), deleteOrder) // PARAM: namespace, name
ordersWorkloadRoutes.PATCH("/", patchOrder) // BODY: json-object
ordersWorkloadRoutes.POST("/", createOrder) // BODY: yaml-object
}
// issuer
issuerWorkloadRoutes := workloadRoutes.Group(fmt.Sprintf("/%s", strings.ToLower(kubernetes.RES_ISSUER)), Auth(dtos.USER), RequireContextId())
{
issuerWorkloadRoutes.GET("/", allIssuers) // PARAM: namespace
issuerWorkloadRoutes.GET("/describe/:namespace/:name", validateParam("namespace", "name"), describeIssuer) // PARAM: namespace, name
issuerWorkloadRoutes.DELETE("/:namespace/:name", validateParam("namespace", "name"), deleteIssuer) // PARAM: namespace, name
issuerWorkloadRoutes.PATCH("/", patchIssuer) // BODY: json-object
issuerWorkloadRoutes.POST("/", createIssuer) // BODY: yaml-object
}
// cluster-issuer
clusterIssuerWorkloadRoutes := workloadRoutes.Group(fmt.Sprintf("/%s", strings.ToLower(kubernetes.RES_CLUSTER_ISSUER)), Auth(dtos.ADMIN), RequireContextId())
{
clusterIssuerWorkloadRoutes.GET("/", allClusterIssuers) // PARAM: -
clusterIssuerWorkloadRoutes.GET("/describe/:name", validateParam("name"), describeClusterIssuer) // PARAM: name
clusterIssuerWorkloadRoutes.DELETE("/:name", validateParam("name"), deleteClusterIssuer) // PARAM: name
clusterIssuerWorkloadRoutes.PATCH("/", patchClusterIssuer) // BODY: json-object
clusterIssuerWorkloadRoutes.POST("/", createClusterIssuer) // BODY: yaml-object
}
// service-account
serviceAccountWorkloadRoutes := workloadRoutes.Group(fmt.Sprintf("/%s", strings.ToLower(kubernetes.RES_SERVICE_ACCOUNT)), Auth(dtos.ADMIN), RequireContextId())
{
serviceAccountWorkloadRoutes.GET("/", allServiceAccounts) // PARAM: namespace
serviceAccountWorkloadRoutes.GET("/describe/:namespace/:name", validateParam("namespace", "name"), describeServiceAccount) // PARAM: namespace, name
serviceAccountWorkloadRoutes.DELETE("/:namespace/:name", validateParam("namespace", "name"), deleteServiceAccount) // PARAM: namespace, name
serviceAccountWorkloadRoutes.PATCH("/", patchServiceAccount) // BODY: json-object
serviceAccountWorkloadRoutes.POST("/", createServiceAccount) // BODY: yaml-object
}
// role
roleWorkloadRoutes := workloadRoutes.Group(fmt.Sprintf("/%s", strings.ToLower(kubernetes.RES_ROLE)), RequireContextId())
{
roleWorkloadRoutes.GET("/", Auth(dtos.USER), allRoles) // PARAM: namespace
roleWorkloadRoutes.GET("/describe/:namespace/:name", Auth(dtos.USER), validateParam("namespace", "name"), describeRole) // PARAM: namespace, name
roleWorkloadRoutes.DELETE("/:namespace/:name", Auth(dtos.ADMIN), validateParam("namespace", "name"), deleteRole) // PARAM: namespace, name
roleWorkloadRoutes.PATCH("/", Auth(dtos.ADMIN), patchRole) // BODY: json-object
roleWorkloadRoutes.POST("/", Auth(dtos.ADMIN), createRole) // BODY: yaml-object
}
// role-binding
roleBindingWorkloadRoutes := workloadRoutes.Group(fmt.Sprintf("/%s", strings.ToLower(kubernetes.RES_ROLE_BINDING)), RequireContextId())
{
roleBindingWorkloadRoutes.GET("/", Auth(dtos.USER), allRoleBindings) // PARAM: namespace
roleBindingWorkloadRoutes.GET("/describe/:namespace/:name", Auth(dtos.USER), validateParam("namespace", "name"), describeRoleBinding) // PARAM: namespace, name
roleBindingWorkloadRoutes.DELETE("/:namespace/:name", Auth(dtos.ADMIN), validateParam("namespace", "name"), deleteRoleBinding) // PARAM: namespace, name
roleBindingWorkloadRoutes.PATCH("/", Auth(dtos.ADMIN), patchRoleBinding) // BODY: json-object
roleBindingWorkloadRoutes.POST("/", Auth(dtos.ADMIN), createRoleBinding) // BODY: yaml-object
}
// cluster-role
clusterRoleWorkloadRoutes := workloadRoutes.Group(fmt.Sprintf("/%s", strings.ToLower(kubernetes.RES_CLUSTER_ROLE)), Auth(dtos.ADMIN), RequireContextId())
{
clusterRoleWorkloadRoutes.GET("/", allClusterRoles) // PARAM: -
clusterRoleWorkloadRoutes.GET("/describe/:name", validateParam("name"), describeClusterRole) // PARAM: name
clusterRoleWorkloadRoutes.DELETE("/:name", validateParam("name"), deleteClusterRole) // PARAM: name
clusterRoleWorkloadRoutes.PATCH("/cluster_role", patchClusterRole) // BODY: json-object
clusterRoleWorkloadRoutes.POST("/cluster_role", createClusterRole) // BODY: yaml-object
}
// cluster-role-binding
clusterRoleBindingWorkloadRoutes := workloadRoutes.Group(fmt.Sprintf("/%s", strings.ToLower(kubernetes.RES_CLUSTER_ROLE_BINDING)), Auth(dtos.ADMIN), RequireContextId())
{
clusterRoleBindingWorkloadRoutes.GET("/", allClusterRoleBindings) // PARAM: -
clusterRoleBindingWorkloadRoutes.GET("/describe/:name", validateParam("name"), describeClusterRoleBinding) // PARAM: name
clusterRoleBindingWorkloadRoutes.DELETE("/:name", validateParam("name"), deleteClusterRoleBinding) // PARAM: name
clusterRoleBindingWorkloadRoutes.PATCH("/", patchClusterRoleBinding) // BODY: json-object
clusterRoleBindingWorkloadRoutes.POST("/", createClusterRoleBinding) // BODY: yaml-object
}
// volume-attachment
volumeAttachmentWorkloadRoutes := workloadRoutes.Group(fmt.Sprintf("/%s", strings.ToLower(kubernetes.RES_VOLUME_ATTACHMENT)), Auth(dtos.ADMIN), RequireContextId())
{
volumeAttachmentWorkloadRoutes.GET("/", allVolumeAttachments) // PARAM: -
volumeAttachmentWorkloadRoutes.GET("/describe/:name", validateParam("name"), describeVolumeAttachment) // PARAM: name
volumeAttachmentWorkloadRoutes.DELETE("/:name", validateParam("name"), deleteVolumeAttachment) // PARAM: name
volumeAttachmentWorkloadRoutes.PATCH("/", patchVolumeAttachment) // BODY: json-object
volumeAttachmentWorkloadRoutes.POST("/", createVolumeAttachment) // BODY: yaml-object
}
// network-policy
networkPolicyWorkloadRoutes := workloadRoutes.Group(fmt.Sprintf("/%s", strings.ToLower(kubernetes.RES_NETWORK_POLICY)), RequireContextId())
{
networkPolicyWorkloadRoutes.GET("/", Auth(dtos.USER), allNetworkPolicies) // PARAM: namespace
networkPolicyWorkloadRoutes.GET("/describe/:namespace/:name", Auth(dtos.USER), validateParam("namespace", "name"), describeNetworkPolicy) // PARAM: namespace, name
networkPolicyWorkloadRoutes.DELETE("/:namespace/:name", Auth(dtos.ADMIN), validateParam("namespace", "name"), deleteNetworkPolicy) // PARAM: namespace, name
networkPolicyWorkloadRoutes.PATCH("/", Auth(dtos.ADMIN), patchNetworkPolicy) // BODY: json-object
networkPolicyWorkloadRoutes.POST("/", Auth(dtos.ADMIN), createNetworkPolicy) // BODY: yaml-object
}
// storage-class
storageClassWorkloadRoutes := workloadRoutes.Group(fmt.Sprintf("/%s", strings.ToLower(kubernetes.RES_STORAGE_CLASS)), RequireContextId())
{
storageClassWorkloadRoutes.GET("/", Auth(dtos.USER), allStorageClasses) // PARAM: namespace
storageClassWorkloadRoutes.GET("/describe/:name", Auth(dtos.USER), validateParam("name"), describeStorageClass) // PARAM: namespace, name
storageClassWorkloadRoutes.DELETE("/:name", Auth(dtos.ADMIN), validateParam("name"), deleteStorageClass) // PARAM: namespace, name
storageClassWorkloadRoutes.PATCH("/", Auth(dtos.ADMIN), patchStorageClass) // BODY: json-object
storageClassWorkloadRoutes.POST("/", Auth(dtos.ADMIN), createStorageClass) // BODY: yaml-object
}
// crds
crdsWorkloadRoutes := workloadRoutes.Group(fmt.Sprintf("/%s", strings.ToLower(kubernetes.RES_CUSTOM_RESOURCE_DEFINITION)), Auth(dtos.ADMIN), RequireContextId())
{
crdsWorkloadRoutes.GET("/", allCrds) // PARAM: -
crdsWorkloadRoutes.GET("/describe/:name", validateParam("name"), Auth(dtos.ADMIN), describeCrd) // PARAM: name
crdsWorkloadRoutes.DELETE("/:name", validateParam("name"), Auth(dtos.ADMIN), deleteCrd) // PARAM: name
crdsWorkloadRoutes.PATCH("/", Auth(dtos.ADMIN), patchCrd) // BODY: json-object
crdsWorkloadRoutes.POST("/", Auth(dtos.ADMIN), createCrd) // BODY: yaml-object
}
// endpoints
endpointsWorkloadRoutes := workloadRoutes.Group(fmt.Sprintf("/%s", strings.ToLower(kubernetes.RES_ENDPOINT)), Auth(dtos.USER), RequireContextId())
{
endpointsWorkloadRoutes.GET("/", allEndpoints) // PARAM: namespace
endpointsWorkloadRoutes.GET("/describe/:namespace/:name", validateParam("namespace", "name"), describeEndpoint) // PARAM: namespace, name
endpointsWorkloadRoutes.DELETE("/:namespace/:name", validateParam("namespace", "name"), deleteEndpoint) // PARAM: namespace, name
endpointsWorkloadRoutes.PATCH("/", patchEndpoint) // BODY: json-object
endpointsWorkloadRoutes.POST("/", createEndpoint) // BODY: yaml-object
}
// leases
leasesWorkloadRoutes := workloadRoutes.Group(fmt.Sprintf("/%s", strings.ToLower(kubernetes.RES_LEASE)), Auth(dtos.USER), RequireContextId())
{
leasesWorkloadRoutes.GET("/", allLeases) // PARAM: namespace
leasesWorkloadRoutes.GET("/describe/:namespace/:name", validateParam("namespace", "name"), describeLease) // PARAM: namespace, name
leasesWorkloadRoutes.DELETE("/:namespace/:name", validateParam("namespace", "name"), deleteLease) // PARAM: namespace, name
leasesWorkloadRoutes.PATCH("/", patchLease) // BODY: json-object
leasesWorkloadRoutes.POST("/", createLease) // BODY: yaml-object
}
// priority-classes
priorityClassesWorkloadRoutes := workloadRoutes.Group(fmt.Sprintf("/%s", strings.ToLower(kubernetes.RES_PRIORITY_CLASS)), Auth(dtos.ADMIN), RequireContextId())
{
priorityClassesWorkloadRoutes.GET("/", allPriorityClasses) // PARAM: -
priorityClassesWorkloadRoutes.GET("/describe/:name", validateParam("name"), describePriorityClass) // PARAM: name
priorityClassesWorkloadRoutes.DELETE("/:name", validateParam("name"), deletePriorityClass) // PARAM: name
priorityClassesWorkloadRoutes.PATCH("/", patchPriorityClass) // BODY: json-object
priorityClassesWorkloadRoutes.POST("/", createPriorityClass) // BODY: yaml-object
}
// volume-snapshots
volumeSnapshotsWorkloadRoutes := workloadRoutes.Group(fmt.Sprintf("/%s", strings.ToLower(kubernetes.RES_VOLUME_SNAPSHOT)), Auth(dtos.USER), RequireContextId())
{
volumeSnapshotsWorkloadRoutes.GET("/", allVolumeSnapshots) // PARAM: namespace
volumeSnapshotsWorkloadRoutes.GET("/describe/:namespace/:name", validateParam("namespace", "name"), describeVolumeSnapshot) // PARAM: namespace, name
volumeSnapshotsWorkloadRoutes.DELETE("/:namespace/:name", validateParam("namespace", "name"), deleteVolumeSnapshot) // PARAM: namespace, name
volumeSnapshotsWorkloadRoutes.PATCH("/", patchVolumeSnapshot) // BODY: json-object
volumeSnapshotsWorkloadRoutes.POST("/", createVolumeSnapshot) // BODY: yaml-object
}
// resource-quota
resourceQuotaWorkloadRoutes := workloadRoutes.Group(fmt.Sprintf("/%s", strings.ToLower(kubernetes.RES_RESOURCE_QUOTA)), Auth(dtos.ADMIN), RequireContextId())
{
resourceQuotaWorkloadRoutes.GET("/", allResourceQuotas) // PARAM: namespace
resourceQuotaWorkloadRoutes.GET("/describe/:namespace/:name", validateParam("namespace", "name"), describeResourceQuota) // PARAM: namespace, name
resourceQuotaWorkloadRoutes.DELETE("/:namespace/:name", validateParam("namespace", "name"), deleteResourceQuota) // PARAM: namespace, name
resourceQuotaWorkloadRoutes.PATCH("/", patchResourceQuota) // BODY: json-object
resourceQuotaWorkloadRoutes.POST("/", createResourceQuota) // BODY: yaml-object
}
// ingress-classes
ingressClassesWorkloadRoutes := workloadRoutes.Group(fmt.Sprintf("/%s", strings.ToLower(kubernetes.RES_INGRESS_CLASS)), Auth(dtos.ADMIN), RequireContextId())
{
ingressClassesWorkloadRoutes.GET("/", allIngressClasses) // PARAM: -
ingressClassesWorkloadRoutes.GET("/describe/:name", validateParam("name"), describeIngressClass) // PARAM: name
ingressClassesWorkloadRoutes.DELETE("/:name", validateParam("name"), deleteIngressClass) // PARAM: name
ingressClassesWorkloadRoutes.PATCH("/", patchIngressClass) // BODY: json-object
ingressClassesWorkloadRoutes.POST("/", createIngressClass) // BODY: yaml-object
}
}
}
// @Tags General
// @Produce json
// @Success 200 {array} kubernetes.K8sNewWorkload
// @Router /backend/workload/templates/ [get]
// @Security Bearer
// @Param string header string true "X-Context-Id"
func allWorkloadTemplates(c *gin.Context) {
c.JSON(http.StatusOK, kubernetes.ListCreateTemplates())
}
// @Tags General
// @Produce json
// @Success 200 {array} string
// @Router /backend/workload/available-resources/ [get]
// @Security Bearer
// @Param string header string true "X-Context-Id"
func allKubernetesResources(c *gin.Context) {
user, err := CheckUserAuthorization(c)
if err != nil || user == nil {
utils.MalformedMessage(c, "User not found.")
return
}
c.JSON(http.StatusOK, kubernetes.WorkloadsForAccesslevel(user.AccessLevel))
}
// ---------------------- NAMESPACES ----------------------
// NAMESPACES
// @Tags Workloads
// @Produce json
// @Success 200 {array} v1.Namespace
// @Router /backend/workload/namespace/ [get]
// @Param namespace query string false "name of the namespace"
// @Security Bearer
// @Param string header string true "X-Context-Id"
func allNamespaces(c *gin.Context) {
c.JSON(http.StatusOK, kubernetes.ListK8sNamespaces("", services.GetGinContextId(c)))
}
// NAMESPACES
// @Tags Workloads
// @Produce json
// @Success 200 {array} v1.Namespace
// @Router /backend/workload/namespace/describe/{name}/ [get]
// @Param name path string true "name of the namespace"
// @Security Bearer
// @Param string header string true "X-Context-Id"
func describeNamespaces(c *gin.Context) {
name := c.Param("name")
c.JSON(http.StatusOK, kubernetes.DescribeK8sNamespace(name, services.GetGinContextId(c)))
}
// NAMESPACES
// @Tags Workloads
// @Produce json
// @Success 201 {object} utils.K8sWorkloadResult
// @Router /backend/workload/namespace [post]
// @Security Bearer
// @Param string header string true "X-Context-Id"
// @Body {"type": "object"}
func createNamespace(c *gin.Context) {
var data v1.Namespace
err := c.MustBindWith(&data, binding.YAML)
if err != nil {
return
}
c.JSON(http.StatusCreated, kubernetes.CreateK8sNamespace(data, services.GetGinContextId(c)))
}
// @Tags Workloads
// @Produce json
// @Success 200 {object} utils.K8sWorkloadResult
// @Router /backend/workload/namespace [patch]
// @Security Bearer
// @Param string header string true "X-Context-Id"
func patchNamespace(c *gin.Context) {
var data v1.Namespace
err := c.MustBindWith(&data, binding.JSON)
if err != nil {
utils.MalformedMessage(c, err.Error())
return
}
utils.HttpRespondForWorkloadResult(c, kubernetes.UpdateK8sNamespace(data, services.GetGinContextId(c)))
}
// NAMESPACES
// @Tags Workloads
// @Produce json
// @Success 200
// @Router /backend/workload/namespace/{name} [delete]
// @Param name path string false "name of the namespace"
// @Security Bearer
// @Param string header string true "X-Context-Id"
func deleteNamespace(c *gin.Context) {
name := c.Param("name")
err := kubernetes.DeleteK8sNamespaceBy(name, services.GetGinContextId(c))
if err != nil {
utils.MalformedMessage(c, err.Error())
return
}
c.Status(http.StatusOK)
}
// ---------------------- PODS ----------------------
// @Tags Workloads
// @Produce json
// @Success 200 {object} utils.K8sWorkloadResult
// @Router /backend/workload/pod/ [get]
// @Param namespace query string false "namespace name"
// @Security Bearer
// @Param string header string true "X-Context-Id"
func allPods(c *gin.Context) {
namespace := c.Query("namespace")
utils.HttpRespondForWorkloadResult(c, kubernetes.AllK8sPods(namespace, services.GetGinContextId(c)))
}
// @Tags Workloads
// @Produce json
// @Success 200 {object} utils.K8sWorkloadResult
// @Router /backend/workload/pod/describe/{namespace}/{name}/ [get]
// @Param namespace path string true "namespace name"
// @Param name path string true "pod name"
// @Security Bearer
// @Param string header string true "X-Context-Id"
func describePod(c *gin.Context) {
namespace := c.Param("namespace")
name := c.Param("name")
utils.HttpRespondForWorkloadResult(c, kubernetes.DescribeK8sPod(namespace, name, services.GetGinContextId(c)))
}
// @Tags Workloads
// @Produce text/event-stream
// @Success 200 {string} string "streaming data"
// @Router /backend/workload/pod/logs/{namespace}/{name}/ [get]
// @Param namespace path string true "namespace name"
// @Param name path string true "pod name"
// @Param since-seconds query string false "since-seconds"
// @Security Bearer
// @Param X-Context-Id header string true "X-Context-Id"
func logsPod(c *gin.Context) {
namespace := c.Param("namespace")
name := c.Param("name")
i, err := strconv.ParseInt(c.Query("since-seconds"), 10, 64)
if err != nil {
i = -1
}
req, err := kubernetes.StreamLog(namespace, name, i, services.GetGinContextId(c))
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
stream, err := req.Stream(context.Background())
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
defer stream.Close()
// set header
c.Writer.Header().Set("Content-Type", "text/event-stream")
c.Writer.Header().Set("Cache-Control", "no-cache")
c.Writer.Header().Set("Connection", "keep-alive")
c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
// get CloseNotify channel
closeChannel := c.Writer.CloseNotify()
go func() {
<-closeChannel
}()
buf := make([]byte, 1024)
c.Stream(func(w io.Writer) bool {
n, err := stream.Read(buf)
if err != nil {
c.SSEvent("error", err.Error())
return false
}
message := string(buf[:n])
c.SSEvent("message", message)
return true
})
}
// @Tags Workloads
// @Produce json
// @Success 200
// @Router /backend/workload/pod/{namespace}/{name} [delete]
// @Param namespace path string true "namespace name"
// @Param name path string true "pod name"
// @Security Bearer
// @Param string header string true "X-Context-Id"
func deletePod(c *gin.Context) {
namespace := c.Param("namespace")
name := c.Param("name")
err := kubernetes.DeleteK8sPodBy(namespace, name, services.GetGinContextId(c))
if err != nil {
utils.MalformedMessage(c, err.Error())
return
}
c.Status(http.StatusOK)
}
// @Tags Workloads
// @Produce json
// @Success 200 {object} utils.K8sWorkloadResult
// @Router /backend/workload/pod [patch]
// @Security Bearer
// @Param string header string true "X-Context-Id"
func patchPod(c *gin.Context) {
var data v1.Pod
err := c.MustBindWith(&data, binding.JSON)
if err != nil {
utils.MalformedMessage(c, err.Error())
return
}
utils.HttpRespondForWorkloadResult(c, kubernetes.UpdateK8sPod(data, services.GetGinContextId(c)))
}
// @Tags Workloads
// @Produce json
// @Success 200 {object} utils.K8sWorkloadResult
// @Router /backend/workload/pod [post]
// @Security Bearer
// @Param string header string true "X-Context-Id"
func createPod(c *gin.Context) {
var data v1.Pod
err := c.MustBindWith(&data, binding.YAML)
if err != nil {
utils.MalformedMessage(c, err.Error())
return
}
utils.HttpRespondForWorkloadResult(c, kubernetes.CreateK8sPod(data, services.GetGinContextId(c)))
}
// ---------------------- DEPLOYMENTS ----------------------
// @Tags Workloads
// @Produce json
// @Success 200 {object} utils.K8sWorkloadResult
// @Router /backend/workload/deployment/ [get]
// @Param namespace query string false "namespace name"
// @Security Bearer
// @Param string header string true "X-Context-Id"
func allDeployments(c *gin.Context) {
namespace := c.Query("namespace")
utils.HttpRespondForWorkloadResult(c, kubernetes.AllK8sDeployments(namespace, services.GetGinContextId(c)))
}
// @Tags Workloads
// @Produce json
// @Success 200 {object} utils.K8sWorkloadResult
// @Router /backend/workload/deployment/describe/{namespace}/{name}/ [get]
// @Param namespace path string true "namespace name"
// @Param name path string true "deployment name"
// @Security Bearer
// @Param string header string true "X-Context-Id"
func describeDeployment(c *gin.Context) {
namespace := c.Param("namespace")
name := c.Param("name")
utils.HttpRespondForWorkloadResult(c, kubernetes.DescribeK8sDeployment(namespace, name, services.GetGinContextId(c)))
}
// @Tags Workloads
// @Produce json
// @Success 200
// @Router /backend/workload/deployment/{namespace}/{name} [delete]
// @Param namespace path string true "namespace name"
// @Param name path string true "deployment name"
// @Security Bearer
// @Param string header string true "X-Context-Id"
func deleteDeployment(c *gin.Context) {
namespace := c.Param("namespace")
name := c.Param("name")
err := kubernetes.DeleteK8sDeploymentBy(namespace, name, services.GetGinContextId(c))
if err != nil {
utils.MalformedMessage(c, err.Error())
return
}
c.Status(http.StatusOK)
}
// @Tags Workloads
// @Produce json
// @Success 200 {object} utils.K8sWorkloadResult
// @Router /backend/workload/deployment [patch]
// @Security Bearer
// @Param string header string true "X-Context-Id"
func patchDeployment(c *gin.Context) {
var data v1Apps.Deployment
err := c.MustBindWith(&data, binding.JSON)
if err != nil {
utils.MalformedMessage(c, err.Error())
return
}
utils.HttpRespondForWorkloadResult(c, kubernetes.UpdateK8sDeployment(data, services.GetGinContextId(c)))
}
// @Tags Workloads
// @Produce json
// @Success 200 {object} utils.K8sWorkloadResult
// @Router /backend/workload/deployment [post]
// @Security Bearer
// @Param string header string true "X-Context-Id"
func createDeployment(c *gin.Context) {
var data v1Apps.Deployment
err := c.MustBindWith(&data, binding.YAML)
if err != nil {
utils.MalformedMessage(c, err.Error())
return
}
utils.HttpRespondForWorkloadResult(c, kubernetes.CreateK8sDeployment(data, services.GetGinContextId(c)))
}
// ---------------------- SERVICES ----------------------
// @Tags Workloads
// @Produce json
// @Success 200 {object} utils.K8sWorkloadResult
// @Router /backend/workload/service/ [get]
// @Security Bearer
// @Param string header string true "X-Context-Id"
// @Param namespace query string false "namespace name"
func allServices(c *gin.Context) {
namespace := c.Query("namespace")
utils.HttpRespondForWorkloadResult(c, kubernetes.AllK8sServices(namespace, services.GetGinContextId(c)))
}
// @Tags Workloads
// @Produce json
// @Success 200 {object} utils.K8sWorkloadResult
// @Router /backend/workload/service/describe/{namespace}/{name}/ [get]
// @Param namespace path string true "namespace name"
// @Param name path string true "service name"
// @Security Bearer
// @Param string header string true "X-Context-Id"
func describeService(c *gin.Context) {
namespace := c.Param("namespace")
name := c.Param("name")
utils.HttpRespondForWorkloadResult(c, kubernetes.DescribeK8sService(namespace, name, services.GetGinContextId(c)))
}
// @Tags Workloads
// @Produce json
// @Success 200
// @Router /backend/workload/service/{namespace}/{name [delete]
// @Security Bearer
// @Param string header string true "X-Context-Id"
// @Param namespace path string true "namespace name"
// @Param name path string true "service name"
func deleteService(c *gin.Context) {
namespace := c.Param("namespace")
name := c.Param("name")
err := kubernetes.DeleteK8sServiceBy(namespace, name, services.GetGinContextId(c))
if err != nil {
utils.MalformedMessage(c, err.Error())
return
}
c.Status(http.StatusOK)
}
// @Tags Workloads
// @Produce json
// @Success 200 {object} utils.K8sWorkloadResult
// @Router /backend/workload/service [patch]
// @Security Bearer
// @Param string header string true "X-Context-Id"
func patchService(c *gin.Context) {
var data v1.Service
err := c.MustBindWith(&data, binding.JSON)
if err != nil {
utils.MalformedMessage(c, err.Error())
return
}
utils.HttpRespondForWorkloadResult(c, kubernetes.UpdateK8sService(data, services.GetGinContextId(c)))
}
// @Tags Workloads
// @Produce json
// @Success 200 {object} utils.K8sWorkloadResult
// @Router /backend/workload/service [post]
// @Security Bearer
// @Param string header string true "X-Context-Id"
func createService(c *gin.Context) {
var data v1.Service
err := c.MustBindWith(&data, binding.YAML)
if err != nil {
utils.MalformedMessage(c, err.Error())
return
}
utils.HttpRespondForWorkloadResult(c, kubernetes.CreateK8sService(data, services.GetGinContextId(c)))
}
// ---------------------- INGRESSES ----------------------
// @Tags Workloads
// @Produce json
// @Success 200 {object} utils.K8sWorkloadResult
// @Router /backend/workload/ingress/ [get]
// @Security Bearer
// @Param string header string true "X-Context-Id"
// @Param namespace query string false "namespace name"
func allIngresses(c *gin.Context) {
namespace := c.Query("namespace")
utils.HttpRespondForWorkloadResult(c, kubernetes.AllK8sIngresses(namespace, services.GetGinContextId(c)))
}
// @Tags Workloads
// @Produce json
// @Success 200 {object} utils.K8sWorkloadResult
// @Router /backend/workload/ingress/describe/{namespace}/{name}/ [get]
// @Param namespace path string true "namespace name"
// @Param name path string true "ingress name"
// @Security Bearer
// @Param string header string true "X-Context-Id"
func describeIngress(c *gin.Context) {
namespace := c.Param("namespace")
name := c.Param("name")
utils.HttpRespondForWorkloadResult(c, kubernetes.DescribeK8sIngress(namespace, name, services.GetGinContextId(c)))
}
// @Tags Workloads
// @Produce json
// @Success 200
// @Router /backend/workload/ingress/{namespace}/{name} [delete]
// @Security Bearer
// @Param string header string true "X-Context-Id"
// @Param namespace path string true "namespace name"
// @Param name path string true "ingress name"
func deleteIngress(c *gin.Context) {
namespace := c.Param("namespace")
name := c.Param("name")
err := kubernetes.DeleteK8sIngressBy(namespace, name, services.GetGinContextId(c))
if err != nil {
utils.MalformedMessage(c, err.Error())
return
}
c.Status(http.StatusOK)
}
// @Tags Workloads
// @Produce json
// @Success 200 {object} utils.K8sWorkloadResult
// @Router /backend/workload/ingress [patch]
// @Security Bearer
// @Param string header string true "X-Context-Id"
func patchIngress(c *gin.Context) {
var data v1Networking.Ingress
err := c.MustBindWith(&data, binding.JSON)
if err != nil {
utils.MalformedMessage(c, err.Error())
return
}
utils.HttpRespondForWorkloadResult(c, kubernetes.UpdateK8sIngress(data, services.GetGinContextId(c)))
}
// @Tags Workloads
// @Produce json
// @Success 200 {object} utils.K8sWorkloadResult
// @Router /backend/workload/ingress [post]
// @Security Bearer
// @Param string header string true "X-Context-Id"
func createIngress(c *gin.Context) {
var data v1Networking.Ingress
err := c.MustBindWith(&data, binding.YAML)
if err != nil {
utils.MalformedMessage(c, err.Error())
return
}
utils.HttpRespondForWorkloadResult(c, kubernetes.CreateK8sIngress(data, services.GetGinContextId(c)))
}
// ---------------------- CONFIGMAPS ----------------------
// @Tags Workloads
// @Produce json
// @Success 200 {object} utils.K8sWorkloadResult
// @Router /backend/workload/configmap/ [get]
// @Security Bearer
// @Param string header string true "X-Context-Id"
// @Param namespace query string false "namespace name"
func allConfigmaps(c *gin.Context) {
namespace := c.Query("namespace")
utils.HttpRespondForWorkloadResult(c, kubernetes.AllK8sConfigmaps(namespace, services.GetGinContextId(c)))
}
// @Tags Workloads
// @Produce json
// @Success 200 {object} utils.K8sWorkloadResult
// @Router /backend/workload/configmap/describe/{namespace}/{name}/ [get]
// @Param namespace path string true "namespace"
// @Param name path string true "configmap name"
// @Security Bearer
// @Param string header string true "X-Context-Id"
func describeConfigmap(c *gin.Context) {
namespace := c.Param("namespace")
name := c.Param("name")
utils.HttpRespondForWorkloadResult(c, kubernetes.DescribeK8sConfigmap(namespace, name, services.GetGinContextId(c)))
}
// @Tags Workloads
// @Produce json
// @Success 200
// @Router /backend/workload/configmap/{namespace}/{name} [delete]
// @Security Bearer
// @Param string header string true "X-Context-Id"
// @Param namespace path string true "namespace"
// @Param name path string true "configmap name"
func deleteConfigmap(c *gin.Context) {
namespace := c.Param("namespace")
name := c.Param("name")
err := kubernetes.DeleteK8sConfigmapBy(namespace, name, services.GetGinContextId(c))
if err != nil {
utils.MalformedMessage(c, err.Error())
return
}
c.Status(http.StatusOK)
}
// @Tags Workloads
// @Produce json
// @Success 200 {object} utils.K8sWorkloadResult
// @Router /backend/workload/configmap [patch]
// @Security Bearer
// @Param string header string true "X-Context-Id"
func patchConfigmap(c *gin.Context) {
var data v1.ConfigMap
err := c.MustBindWith(&data, binding.JSON)
if err != nil {
utils.MalformedMessage(c, err.Error())
return
}
utils.HttpRespondForWorkloadResult(c, kubernetes.UpdateK8sConfigMap(data, services.GetGinContextId(c)))
}
// @Tags Workloads
// @Produce json
// @Success 200 {object} utils.K8sWorkloadResult
// @Router /backend/workload/configmap [post]
// @Security Bearer
// @Param string header string true "X-Context-Id"
func createConfigmap(c *gin.Context) {
var data v1.ConfigMap
err := c.MustBindWith(&data, binding.YAML)
if err != nil {
utils.MalformedMessage(c, err.Error())
return
}
utils.HttpRespondForWorkloadResult(c, kubernetes.CreateK8sConfigMap(data, services.GetGinContextId(c)))
}
// ---------------------- SECRETS ----------------------
// @Tags Workloads
// @Produce json
// @Success 200 {object} utils.K8sWorkloadResult
// @Router /backend/workload/secret/ [get]
// @Security Bearer
// @Param string header string true "X-Context-Id"
// @Param namespace query string false "namespace name"
func allSecrets(c *gin.Context) {
namespace := c.Query("namespace")
utils.HttpRespondForWorkloadResult(c, kubernetes.AllK8sSecrets(namespace, services.GetGinContextId(c)))
}
// @Tags Workloads
// @Produce json
// @Success 200 {object} utils.K8sWorkloadResult
// @Router /backend/workload/secret/describe/{namespace}/{name}/ [get]
// @Param namespace path string true "namespace name"
// @Param name path string true "secret name"
// @Security Bearer
// @Param string header string true "X-Context-Id"
func describeSecret(c *gin.Context) {
namespace := c.Param("namespace")
name := c.Param("name")
utils.HttpRespondForWorkloadResult(c, kubernetes.DescribeK8sSecret(namespace, name, services.GetGinContextId(c)))
}
// @Tags Workloads
// @Produce json
// @Success 200
// @Router /backend/workload/secret/{namespace}/{name} [delete]
// @Param namespace path string true "namespace name"
// @Param name path string true "secret name"
// @Security Bearer
// @Param string header string true "X-Context-Id"