Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add admin username to values #72

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkg/appinstaller/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ func (h *HelmOps) setValues() (values map[string]interface{}, err error) {
}
gpuType, err := utils.FindGpuTypeFromNodes(h.ctx, kClient)
if err != nil {
klog.Errorf("Failed to get gpuType err=%v", err)
return values, err
}
values["gpu"] = gpuType
Expand All @@ -436,6 +437,11 @@ func (h *HelmOps) setValues() (values map[string]interface{}, err error) {
sharedLibPath := os.Getenv("SHARED_LIB_PATH")
values["sharedlib"] = sharedLibPath

admin, err := kubesphere.GetAdminUsername(context.TODO(), h.kubeConfig)
if err != nil {
return values, err
}
values["admin"] = admin
return values, err
}

Expand Down
32 changes: 32 additions & 0 deletions pkg/kubesphere/kubesphere.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,35 @@ func GetUserCPULimit(ctx context.Context, kubeConfig *rest.Config, username stri
func GetUserMemoryLimit(ctx context.Context, kubeConfig *rest.Config, username string) (string, error) {
return GetUserAnnotation(ctx, kubeConfig, username, userAnnotationMemoryLimitKey)
}

// GetAdminUsername returns admin username, an error if there is any.
func GetAdminUsername(ctx context.Context, kubeConfig *rest.Config) (string, error) {
gvr := schema.GroupVersionResource{
Group: "iam.kubesphere.io",
Version: "v1alpha2",
Resource: "users",
}
client, err := dynamic.NewForConfig(kubeConfig)
if err != nil {
return "", err
}
data, err := client.Resource(gvr).List(ctx, metav1.ListOptions{})
if err != nil {
klog.Errorf("Failed to get user list err=%v", err)
return "", err
}

var admin string
for _, u := range data.Items {
if u.Object == nil {
continue
}
annotations := u.GetAnnotations()
if annotations["bytetrade.io/owner-role"] == "platform-admin" {
admin = u.GetName()
break
}
}

return admin, nil
}
Loading