Skip to content

Commit 22b830a

Browse files
committed
Make ResolvedExec inline ContainerInfo to avoid duplicating information
Signed-off-by: Angel Misevski <[email protected]>
1 parent 6073db5 commit 22b830a

File tree

6 files changed

+15
-21
lines changed

6 files changed

+15
-21
lines changed

api/model/model_types.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,14 @@ type MachineIdentifier struct {
3232
}
3333

3434
type ContainerInfo struct {
35-
ContainerName string
36-
PodName string
35+
PodName string `json:"pod"`
36+
ContainerName string `json:"container"`
3737
}
3838

3939
//ResolvedExec holds info client might send to create exec
4040
type ResolvedExec struct {
41-
PodName string `json:"pod"`
42-
ContainerName string `json:"container"`
43-
Cmd []string `json:"cmd"`
41+
ContainerInfo
42+
Cmd []string `json:"cmd"`
4443
}
4544

4645
// Todo code Refactoring: MachineExec should be simple object for exec creation, without any business logic

api/rest/common.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,11 @@ import (
1616
"github.com/eclipse/che-machine-exec/api/model"
1717
)
1818

19-
func HandleKubeConfigCreation(kubeConfigParams *model.KubeConfigParams, resolvedExec *model.ResolvedExec) error {
19+
func HandleKubeConfigCreation(kubeConfigParams *model.KubeConfigParams, containerInfo *model.ContainerInfo) error {
2020
if kubeConfigParams.Username == "" {
2121
kubeConfigParams.Username = "Developer"
2222
}
2323

24-
err := execManager.CreateKubeConfig(kubeConfigParams, &model.ContainerInfo{
25-
ContainerName: resolvedExec.ContainerName,
26-
PodName: resolvedExec.PodName,
27-
})
24+
err := execManager.CreateKubeConfig(kubeConfigParams, containerInfo)
2825
return err
2926
}

api/rest/execInit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func HandleInit(c *gin.Context) {
5656
return
5757
}
5858

59-
err := HandleKubeConfigCreation(&kubeConfigParams, execRequest)
59+
err := HandleKubeConfigCreation(&kubeConfigParams, &execRequest.ContainerInfo)
6060
if err != nil {
6161
rest.WriteResponse(c, http.StatusInternalServerError, err.Error())
6262
return

api/rest/execKubeConfig.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func HandleKubeConfig(c *gin.Context) {
5858
return
5959
}
6060

61-
err := HandleKubeConfigCreation(&kubeConfigParams, execRequest)
61+
err := HandleKubeConfigCreation(&kubeConfigParams, &execRequest.ContainerInfo)
6262

6363
if err != nil {
6464
logrus.Errorf("Unable to create kubeconfig. Cause: %s", err.Error())

exec/kubernetes_exec_manager.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ func (manager *KubernetesExecManager) Resolve(container, token string) (*model.R
9494
logrus.Printf("%s is successfully resolved in auto discovered container %s/%s", resolvedCmd,
9595
containerInfo.PodName, containerInfo.ContainerName)
9696
return &model.ResolvedExec{
97-
PodName: containerInfo.PodName,
98-
ContainerName: containerInfo.ContainerName,
97+
ContainerInfo: *containerInfo,
9998
Cmd: resolvedCmd,
10099
}, nil
101100
} else {
@@ -128,8 +127,7 @@ func (manager *KubernetesExecManager) findFirstAvailable(k8sAPI *client.K8sAPI,
128127
logrus.Printf("%s is successfully resolved in auto discovered container %s/%s", resolvedCmd,
129128
containerInfo.PodName, containerInfo.ContainerName)
130129
return &model.ResolvedExec{
131-
PodName: containerInfo.PodName,
132-
ContainerName: containerInfo.ContainerName,
130+
ContainerInfo: *containerInfo,
133131
Cmd: resolvedCmd,
134132
}, nil
135133
}

mocks/ExecManager.go

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)