feat(k8s): add endpoint that proxies CB-Spider's K8s Cluster Token API#2366
feat(k8s): add endpoint that proxies CB-Spider's K8s Cluster Token API#2366cb-github-robot merged 3 commits intocloud-barista:mainfrom
Conversation
seokho-son
left a comment
There was a problem hiding this comment.
@hanizang77 업데이트 감사합니다. :)
코드 관리 관점에서, 의견들이 있어서 공유 드립니다.
| // @Produce json | ||
| // @Param nsId path string true "Namespace ID" default(default) | ||
| // @Param k8sClusterId path string true "K8sCluster ID" default(k8scluster01) | ||
| // @Success 200 {object} resource.SpiderClusterTokenResponse |
There was a problem hiding this comment.
@hanizang77
기존 CB-TB 컨벤션에 따라서,
CB-Spider 가 상위로 드러날 필요가 없는 부분(특히 API 측면)에 대해서는,
CB-TB의 용어 및 관점으로 내용을 정리해서 내보낼 필요가 있습니다. (사용자에게 CB-Spider에 대한 내용을 의도적으로 드러내신 것이라면 알려주세요.)
- // @description Proxies CB-Spider's cluster token API and returns an ExecCredential token
- resource.SpiderClusterTokenResponse
src/interface/rest/server/server.go
Outdated
| // Echo router gives priority to static segments (/token) over param segments (:k8sClusterId), | ||
| // so this does not conflict with the existing GET /:nsId/k8sCluster/:k8sClusterId route |
There was a problem hiding this comment.
이 코멘트는 어떤 측면에서 추가해두신 것일까요?
업스트림 측면에서 (다른 기여자나 개발자에게) 도움이 되는 코멘트인지 확신이 없습니다.
| if err != nil { | ||
| mapA := map[string]string{"message": "Failed to get token for K8sCluster " + k8sClusterId + ": " + err.Error()} | ||
| return c.JSON(http.StatusInternalServerError, &mapA) | ||
| } | ||
| return c.JSON(http.StatusOK, res) |
There was a problem hiding this comment.
return clientManager.EndRequestWithLog(c, err, content)
이 패턴을 쓰는 것이 바람직합니다. 그러나, k8s 관련 코드들은 아직 정리가 전반적으로 되어 있지 않아서, 일단 api를 신규로 추가하실 때는 살펴봐주시면 좋을 것 같습니다.
src/core/resource/k8scluster.go
Outdated
| // SpiderClusterTokenResponse mirrors CB-Spider's ClusterTokenResponse for ExecCredential passthrough. | ||
| type SpiderClusterTokenResponse struct { | ||
| ApiVersion string `json:"apiVersion"` | ||
| Kind string `json:"kind"` | ||
| Status SpiderClusterTokenStatus `json:"status"` | ||
| } | ||
|
|
||
| type SpiderClusterTokenStatus struct { | ||
| Token string `json:"token"` | ||
| } |
There was a problem hiding this comment.
https://github.com/cloud-barista/cb-tumblebug/blob/main/src/core/model/k8scluster.go
model 쪽에 들어가는게 적절하지 않을까요?
아니면, Spider 앞을 소문자로 변경하여, 활용 범위를 축소하는 방법도 있습니다.
|
@seokho-son 코드와 주석 모두 CB-Spider의 흔적을 의도적으로 드러냈는데, 사용자 관점이 아니라 개인적인 개발 편의만 반영된 것 같습니다. CB-TB 용어와 관점으로 정리하겠습니다.
|
|
@seokho-son 리뷰 감사합니다. 지적해주신 내용을 모두 반영했습니다. 반영된 코드로 AWS & GCP 토큰 발급 및 kubectl을 통한 클러스터 정보 조회까지 가능함을 확인했습니다. |
src/core/model/k8scluster.go
Outdated
| Status K8sClusterTokenStatus `json:"status"` | ||
| } | ||
|
|
||
| // K8sClusterTokenStatus holds the token value for K8s cluster authentication. | ||
| type K8sClusterTokenStatus struct { | ||
| Token string `json:"token"` | ||
| } |
There was a problem hiding this comment.
// K8sClusterTokenStatus holds the token value for K8s cluster authentication.
type K8sClusterTokenStatus struct {
Token string json:"token"
}
이 구조체를 굳이 별도로 정의할 필요가 있을까요?
활용처가 많이 있거나 앞으로 확장될 가능성이 있는 상태인지요?
There was a problem hiding this comment.
K8sClusterTokenStatus는 향후 토큰 만료 처리 등의 필드 확장을 염두에 두고 분리해 두었으나, 당장 확장 계획이 없으므로 합쳐두는 편이 좋을것 같습니다.
혹시 모를 후속 구현(Option C: exec 블록 자동 해소)에서도 .Status.Token 문자열만 접근하면 충분해보입니다.
There was a problem hiding this comment.
@seokho-son 항상 빠르고 정확한 피드백 감사합니다. 조언해주신것처럼 Kubernetes 공식 ExecCredential 명세에 따라 아래과 같이 조정해보겠습니다.
// K8sClusterTokenResponse is the response struct for the K8sCluster token API.
// It wraps an ExecCredential object that kubectl can use directly for exec-based auth.
type K8sClusterTokenResponse struct {
ExecCredential ExecCredential `json:"execCredential"`
}
// ExecCredential mirrors the Kubernetes ExecCredential format (client.authentication.k8s.io/v1).
// kubectl parses this structure when an exec-based kubeconfig is used.
// Ref: https://kubernetes.io/docs/reference/config-api/client-authentication.v1/
type ExecCredential struct {
ApiVersion string `json:"apiVersion"`
Kind string `json:"kind"`
Status ExecCredentialStatus `json:"status"`
}
// ExecCredentialStatus holds credentials for the transport to use.
// Mirrors the Kubernetes ExecCredentialStatus (client.authentication.k8s.io/v1).
type ExecCredentialStatus struct {
Token string `json:"token"`
}To support token-based kubeconfig access for GCP, AWS, and NCP
Move token response types to core/model, remove CB-Spider references from godoc, and apply EndRequestWithLog pattern
|
/approve |
Summary
Adds
GET /ns/{nsId}/k8sCluster/{k8sClusterId}/tokenthat proxies CB-Spider'sGenerateClusterTokenAPI, so external consumers (e.g., M-CMP) can obtain cluster access tokens (AWS, GCP, and NCP) through TB without direct Spider access.Related to #2348
Test Results
Successfully retrieved tokens for AWS, GCP, and NCP clusters and verified cluster access via
kubectl get nodes.k8s-aws-v1...)ya29.c...)status.tokenNotes
status.tokeninstead of a bearer token; consumers must detect and handle this case