Cilium CLI 오픈소스 기여

jaehan·2025년 5월 18일

TL;DR

EKS에서 cilium cli를 통해 install을 실행할 때 current-context 값이 32자를 넘어가면 TLS CN 길이 제한 때문에 설치가 실패하는 문제가 발생했습니다.
이에 EKS 환경에서 설치하는 경우에 ARN을 자동으로 잘라서 유효한 클러스터 이름으로 변환하도록 개선했습니다.

문제 상황

https://docs.cilium.io/en/stable/gettingstarted/k8s-install-default/

위 Cilium Doc의 EKS에 Cilium을 install 하는 방법을 따라하는 경우 아래와 같이 에러가 발생했습니다.

jaehan 🚀  ~
 cilium install --version 1.16.5
🔮 Auto-detected Kubernetes kind: EKS
ℹ️  Using Cilium version 1.16.5
🔮 Auto-detected cluster name: arn:aws:eks:ap-northeast-2:730904690368:cluster/test-cluster
🔮 Auto-detected kube-proxy has been installed
🔥 Patching the "aws-node" DaemonSet to evict its pods...

Error: Unable to install Cilium: execution error at (cilium/templates/validate.yaml:144:5): The cluster name is invalid: must not be more than 32 characters. Configure 'upgradeCompatibility' to 1.15 or earlier to temporarily skip this check at your own risk

에러 로그 중 The cluster name is invalid: must not be more than 32 characters. 해당 부분을 통해 cluster name과 관련된 문제 상황임을 인지했습니다.

왜 이런 일이 벌어졌을까?

cilium cli는 설치 과정에서 --set cluster.name이 없으면 current-context를 사용합니다.

EKS context는 다음처럼 ARN 전체가 들어가 있어서 길이가 쉽게 32자를 초과합니다.

arn:aws:eks:ap-northeast-2:123456789012:cluster/my-eks-cluster

TLS 인증서의 CN(Common Name)은 [RFC 5280]에 따라 최대 64자이며, cilium은 앞뒤로 추가 문자열을 붙이기 때문에 실제 클러스터 이름은 32자로 제한함을 알 수 있었습니다.

CSP별 current-context Cluster Name 비교

다른 CSP에서 클러스터를 생성했을 때, current-context에 어떻게 cluster name이 반영되는지 알아본 결과입니다.
아래에서 보이듯이 EKS의 경우 여러 metadata가 붙어 쉽게 32자를 넘는 것을 볼 수 있었습니다.

  • AWS EKS
current-context: arn:aws:eks:region:account-id:cluster/my-eks-cluster
  • Google GKE
current-context: gke_my-project_us-central1_my-gke-cluster
  • Azure AKS
current-context: my-aks-cluster

기여 내역

cilium cli가 Kubernetes Kind를 Auto-detect할 때, EKS인 경우에 좀 더 스마트하게 클러스터 이름을 추출하게끔 로직을 추가하였습니다.

auto decect logic code

func getClusterName(helmValues map[string<]interface{}) string {
	clusterName, _, _ := unstructured.NestedString(helmValues, "cluster", "name")
	return clusterName
}

func trimEKSClusterARN(fullARN string) string {
	const prefix = "cluster/"
	idx := strings.LastIndex(fullARN, prefix)
	if idx == -1 {
		return fullARN
	}
	idx += len(prefix)
	if idx < len(fullARN) {
		return fullARN[idx:]
	}

	return ""
}

func (k *K8sInstaller) autodetectAndValidate(ctx context.Context, helmValues map[string]interface{}) error {
	k.autodetect(ctx)

	k.Log("ℹ️  Using Cilium version %s", k.chartVersion)

	clusterName := getClusterName(helmValues)
	if clusterName != "" {
		k.params.ClusterName = clusterName
	}

	if k.params.ClusterName == "" {
		if k.flavor.ClusterName != "" {
			// Neither underscores, dots nor colons are allowed as part of the cluster name.
			name := strings.NewReplacer("_", "-", ".", "-", ":", "-").Replace(k.flavor.ClusterName)

			if k.flavor.Kind == k8s.KindEKS {
				name = trimEKSClusterARN(name)
			}

			k.Log("🔮 Auto-detected cluster name: %s", name)
			k.params.ClusterName = name
		}
	} else {
		k.Log("ℹ️  Using cluster name %q", k.params.ClusterName)
	}

	if err := k.detectDatapathMode(helmValues); err != nil {
		return err
	}

	k.autodetectKubeProxy(ctx, helmValues)
	return nil
}

After

jaehan 🚀  ~/projects/cilium/cilium-cli/release   main ±
 cilium install --version 1.16.5
🔮 Auto-detected Kubernetes kind: EKS
ℹ️  Using Cilium version 1.16.5
🔮 Auto-detected cluster name: test-cluster
🔮 Auto-detected kube-proxy has been installed
🔥 Patching the "aws-node" DaemonSet to evict its pods...

참고 링크

Pull Request Link

profile
공부공부

0개의 댓글