Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Atanas Todorov committed Dec 16, 2024
1 parent eddef8d commit 958991c
Showing 1 changed file with 96 additions and 0 deletions.
96 changes: 96 additions & 0 deletions starlark/ucp_provider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// Copyright (c) 2020 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package starlark

import (
"context"
"fmt"

"github.com/pkg/errors"
"go.starlark.net/starlark"
"go.starlark.net/starlarkstruct"
)

// UcpProviderFn is a built-in starlark function that collects Kubconfigs for all available UCP workspaces
// Starlark format: ucp_provider(kube_config=kube_config(),workspace=<name>)
func UcpProviderFn(thread *starlark.Thread, _ *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) {

var (
workspace string
mgmtKubeConfig *starlarkstruct.Struct
)

err := starlark.UnpackArgs("ucp_provider", args, kwargs,
"mgmt_kube_config", &mgmtKubeConfig,
"workspace?", &workspace)
if err != nil {
return starlark.None, errors.Wrap(err, "failed to unpack input arguments")
}

ctx, ok := thread.Local(identifiers.scriptCtx).(context.Context)
if !ok || ctx == nil {
return starlark.None, fmt.Errorf("script context not found")
}

if mgmtKubeConfig == nil {
mgmtKubeConfig = thread.Local(identifiers.kubeCfg).(*starlarkstruct.Struct)
}
//mgmtKubeConfigPath, err := getKubeConfigPathFromStruct(mgmtKubeConfig)
//if err != nil {
// return starlark.None, errors.Wrap(err, "failed to extract management kubeconfig")
//}

// if workload cluster is not supplied, then the resources for the management cluster
// should be enumerated
workspaceName := workspace
if workspaceName == "" {
//config, err := k8s.LoadKubeCfg(mgmtKubeConfigPath)
if err != nil {
return starlark.None, errors.Wrap(err, "failed to load kube config")
}
//workspaceName, err = config.GetClusterName()
//if err != nil {
// return starlark.None, errors.Wrap(err, "cannot find cluster with name "+wo)
//}
}
//
//providerConfigPath, err := provider.KubeConfig(mgmtKubeConfigPath, clusterName, namespace)
//if err != nil {
// return starlark.None, err
//}
//
//nodeAddresses, err := k8s.GetNodeAddresses(ctx, providerConfigPath, toSlice(names), toSlice(labels))
//if err != nil {
// return starlark.None, errors.Wrap(err, "could not fetch host addresses")
//}

// dictionary for capa provider struct
//capaProviderDict := starlark.StringDict{
// "kind": starlark.String(identifiers.capaProvider),
// "transport": starlark.String("ssh"),
// "kube_config": starlark.String(providerConfigPath),
//}

//// add node info to dictionary
//var nodeIps []starlark.Value
//for _, node := range nodeAddresses {
// nodeIps = append(nodeIps, starlark.String(node))
//}
//capaProviderDict["hosts"] = starlark.NewList(nodeIps)
//
//sshConfigDict := starlark.StringDict{}
//sshConfig.ToStringDict(sshConfigDict)
//
//// modify ssh config jump credentials, if not specified
//if _, err := sshConfig.Attr("jump_host"); err != nil {
// sshConfigDict["jump_host"] = starlark.String(bastionIpAddr)
//}
//if _, err := sshConfig.Attr("jump_user"); err != nil {
// sshConfigDict["jump_user"] = starlark.String("ubuntu")
//}
//capaProviderDict[identifiers.sshCfg] = starlarkstruct.FromStringDict(starlark.String(identifiers.sshCfg), sshConfigDict)

//return starlarkstruct.FromStringDict(starlark.String(identifiers.capaProvider), capaProviderDict), nil
return nil, nil
}

0 comments on commit 958991c

Please sign in to comment.