Skip to content

Commit 854d1c7

Browse files
authored
fix: post api fixes iteration-1 (#6835)
* docs: deployment template api spec fixes * fix: post api fixes iteration 1 * fix: post api fixes iteration 1.1
1 parent 075b680 commit 854d1c7

File tree

6 files changed

+69
-38
lines changed

6 files changed

+69
-38
lines changed

api/k8s/application/k8sApplicationRestHandler.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,14 +1002,19 @@ func (handler *K8sApplicationRestHandlerImpl) CreateEphemeralContainer(w http.Re
10021002
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
10031003
return
10041004
}
1005-
if err = handler.validator.Struct(request); err != nil || (request.BasicData == nil && request.AdvancedData == nil) {
1006-
if err != nil {
1007-
err = errors.New("invalid request payload")
1008-
}
1009-
handler.logger.Errorw("invalid request payload", "err", err, "payload", request)
1005+
if request.BasicData == nil && request.AdvancedData == nil {
1006+
err = errors.New("invalid request payload, neither basic data nor advanced data provided")
1007+
handler.logger.Errorw("invalid request payload missing basic data and invalid data", "err", err, "payload", request)
10101008
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
10111009
return
10121010
}
1011+
err = handler.validator.Struct(request)
1012+
if err != nil {
1013+
handler.logger.Errorw("invalid request payload", "err", err, "payload", request)
1014+
//common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
1015+
common.HandleValidationErrors(w, r, err)
1016+
return
1017+
}
10131018
// check for super admin
10141019
restricted := handler.restrictTerminalAccessForNonSuperUsers(w, token)
10151020
if restricted {

pkg/cluster/environment/bean/ephemeralContainerBean.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
)
77

88
type EphemeralContainerRequest struct {
9-
BasicData *EphemeralContainerBasicData `json:"basicData"`
9+
BasicData *EphemeralContainerBasicData `json:"basicData" validate:"required"`
1010
AdvancedData *EphemeralContainerAdvancedData `json:"advancedData"`
1111
Namespace string `json:"namespace" validate:"required"`
1212
ClusterId int `json:"clusterId" validate:"gt=0"`
@@ -18,13 +18,13 @@ type EphemeralContainerRequest struct {
1818
}
1919

2020
type EphemeralContainerAdvancedData struct {
21-
Manifest string `json:"manifest"`
21+
Manifest string `json:"manifest" validate:"required"`
2222
}
2323

2424
type EphemeralContainerBasicData struct {
25-
ContainerName string `json:"containerName"`
26-
TargetContainerName string `json:"targetContainerName"`
27-
Image string `json:"image"`
25+
ContainerName string `json:"containerName" validate:"required"`
26+
TargetContainerName string `json:"targetContainerName" validate:"required"`
27+
Image string `json:"image" validate:"required"`
2828
}
2929

3030
func (request EphemeralContainerRequest) GetContainerBean() repository.EphemeralContainerBean {

pkg/k8s/bean/bean.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type ResourceRequestBean struct {
3333
DevtronAppIdentifier *bean.DevtronAppIdentifier `json:"-"` // For Devtron App Resources
3434
ClusterId int `json:"clusterId"` // clusterId is used when request is for direct cluster (not for helm release)
3535
ExternalArgoApplicationName string `json:"externalArgoApplicationName,omitempty"`
36-
ExternalFluxAppIdentifier *bean2.FluxAppIdentifier `json: "-"`
36+
ExternalFluxAppIdentifier *bean2.FluxAppIdentifier `json:"-"`
3737
ExternalArgoAppIdentifier *bean3.ArgoAppIdentifier `json:"-"`
3838
}
3939

specs/application/application-management.yaml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,10 @@ paths:
123123
in: query
124124
required: true
125125
schema:
126-
type: string
127-
enum: ["argo", "helm", "flux"]
128-
example: "argo"
126+
type: integer
127+
enum: [1, 2, 3]
128+
description: "App type identifier: 1=Helm, 2=Argo, 3=Flux"
129+
example: 2
129130
requestBody:
130131
required: true
131132
content:
@@ -191,9 +192,10 @@ paths:
191192
in: query
192193
required: true
193194
schema:
194-
type: string
195-
enum: ["argo", "helm", "flux"]
196-
example: "argo"
195+
type: integer
196+
enum: [1, 2, 3]
197+
description: "App type identifier: 1=Helm, 2=Argo, 3=Flux"
198+
example: 2
197199
requestBody:
198200
required: true
199201
content:

specs/kubernetes/apis.yaml

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,24 @@ components:
4444

4545
K8sRequestDto:
4646
type: object
47+
required:
48+
- resourceIdentifier
4749
properties:
4850
resourceIdentifier:
4951
$ref: '#/components/schemas/ResourceIdentifier'
5052
patch:
5153
type: string
52-
description: patch data for update operations
54+
description: |
55+
JSON patch data for update operations. Contains the complete Kubernetes manifest
56+
for the resource being updated/edited.
57+
example: '{"apiVersion":"v1","kind":"Pod","metadata":{"name":"my-pod","namespace":"default"},"spec":{"containers":[{"name":"nginx","image":"nginx:1.25"}]}}'
58+
forceDelete:
59+
type: boolean
60+
nullable: true
61+
description: |
62+
Force delete the resource. When true, the resource will be deleted immediately
63+
without waiting for graceful termination. Only applicable for delete operations.
64+
example: false
5365

5466
ResourceIdentifier:
5567
type: object
@@ -64,25 +76,28 @@ components:
6476
$ref: '#/components/schemas/GroupVersionKind'
6577
required:
6678
- name
67-
- namespace
68-
- groupVersionKind
79+
- namespace
80+
- groupVersionKind
6981

7082
GroupVersionKind:
7183
type: object
84+
required:
85+
- Group
86+
- Version
87+
- Kind
7288
properties:
73-
group:
89+
Group:
7490
type: string
75-
description: API group
76-
version:
91+
description: API group (capitalized field name as per Kubernetes API)
92+
example: ""
93+
Version:
7794
type: string
78-
description: API version
79-
kind:
95+
description: API version (capitalized field name as per Kubernetes API)
96+
example: "v1"
97+
Kind:
8098
type: string
81-
description: resource kind
82-
required:
83-
- group
84-
- version
85-
- kind
99+
description: Resource kind (capitalized field name as per Kubernetes API)
100+
example: "Pod"
86101

87102
ManifestResponse:
88103
type: object
@@ -373,14 +388,14 @@ paths:
373388
description: Internal server error
374389
put:
375390
summary: Update Kubernetes resource
376-
description: Updates an existing Kubernetes resource manifest
391+
description: Updates an existing Kubernetes resource manifest using patch data
377392
operationId: UpdateResource
378393
requestBody:
379394
required: true
380395
content:
381396
application/json:
382397
schema:
383-
$ref: '#/components/schemas/ResourceRequestObject'
398+
$ref: '#/components/schemas/ResourceRequestBean'
384399
responses:
385400
"200":
386401
description: Updated resource manifest
@@ -454,11 +469,11 @@ paths:
454469
description: Fetches events for Kubernetes resources
455470
operationId: ListEvents
456471
requestBody:
457-
required: false
472+
required: true
458473
content:
459474
application/json:
460475
schema:
461-
$ref: '#/components/schemas/ResourceRequestObject'
476+
$ref: '#/components/schemas/ResourceRequestBean'
462477
responses:
463478
"200":
464479
description: Resource events

specs/kubernetes/ephemeral-containers.yaml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ components:
106106
schemas:
107107
EphemeralContainerRequest:
108108
type: object
109+
description: |
110+
Request to create an ephemeral container. Either basicData or advancedData is required.
111+
If both are provided, advancedData takes priority over basicData.
109112
properties:
110113
basicData:
111114
$ref: "#/components/schemas/EphemeralContainerBasicData"
@@ -121,16 +124,16 @@ components:
121124
podName:
122125
type: string
123126
description: Name of the pod
124-
userId:
125-
type: integer
126-
description: User ID
127127
externalArgoApplicationName:
128128
type: string
129129
description: Name of the external Argo application (if applicable)
130130
required:
131131
- namespace
132132
- clusterId
133133
- podName
134+
anyOf:
135+
- required: ["basicData"]
136+
- required: ["advancedData"]
134137
EphemeralContainerBasicData:
135138
type: object
136139
properties:
@@ -149,10 +152,16 @@ components:
149152
- image
150153
EphemeralContainerAdvancedData:
151154
type: object
155+
description: |
156+
Advanced configuration for ephemeral container using Kubernetes EphemeralContainer specification.
157+
For complete field reference, see: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.34/#ephemeralcontainer-v1-core
152158
properties:
153159
manifest:
154160
type: string
155-
description: Kubernetes manifest for the ephemeral container
161+
description: |
162+
Kubernetes manifest for the ephemeral container in JSON format.
163+
Should conform to the EphemeralContainer v1 core specification.
164+
Reference: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.34/#ephemeralcontainer-v1-core
156165
PodContainerList:
157166
type: object
158167
properties:

0 commit comments

Comments
 (0)