Skip to content

Commit

Permalink
Reverting changes
Browse files Browse the repository at this point in the history
Signed-off-by: PrimalPimmy <Prashant20.pm@gmail.com>
  • Loading branch information
PrimalPimmy committed Jul 24, 2024
1 parent 645631e commit a144351
Showing 1 changed file with 28 additions and 35 deletions.
63 changes: 28 additions & 35 deletions controllers/pkg/reconcilers/spire-bootstrap/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
reconcilerinterface "github.com/nephio-project/nephio/controllers/pkg/reconcilers/reconciler-interface"
"github.com/nephio-project/nephio/controllers/pkg/resource"
vaultClient "github.com/nephio-project/nephio/controllers/pkg/vault-client"
"gopkg.in/yaml.v2"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes"
Expand All @@ -39,12 +38,14 @@ import (
v1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
capiv1beta1 "sigs.k8s.io/cluster-api/api/v1beta1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/yaml"
)

func init() {
Expand Down Expand Up @@ -369,44 +370,36 @@ func (r *reconciler) createKubeconfigConfigMap(ctx context.Context, clientset *k
}
caCert := configMap.Data["ca.crt"]

kubeconfig := map[string]interface{}{
"apiVersion": "v1",
"kind": "Config",
"clusters": []map[string]interface{}{
{
"name": "regional",
"cluster": map[string]string{
"certificate-authority-data": base64.StdEncoding.EncodeToString([]byte(caCert)),
"server": clientset.RESTClient().Get().URL().String(),
},
},
},
"contexts": []map[string]interface{}{
{
"context": map[string]string{
"cluster": clustername,
"namespace": "spire",
"user": "spire-kubeconfig",
},
},
},
"current-context": "spire-kubeconfig@regional",
"users": []map[string]interface{}{
{
"name": "spire-kubeconfig",
"user": map[string]string{
"token": token,
},
},
},
clusters := make(map[string]*clientcmdapi.Cluster)
clusters["default-cluster"] = &clientcmdapi.Cluster{
Server: clientset.RESTClient().Get().URL().String(),
CertificateAuthorityData: []byte(caCert),
}

yamlData, err := yaml.Marshal(kubeconfig)
if err != nil {
// Handle error
contexts := make(map[string]*clientcmdapi.Context)
contexts["default-context"] = &clientcmdapi.Context{
Cluster: "default-cluster",
Namespace: "spire",
AuthInfo: "spire",
}

authinfos := make(map[string]*clientcmdapi.AuthInfo)
authinfos["spire"] = &clientcmdapi.AuthInfo{
Token: string(token),
}

formattedKubeconfig := string(yamlData)
clientConfig := clientcmdapi.Config{
Kind: "Config",
APIVersion: "v1",
Clusters: clusters,
Contexts: contexts,
CurrentContext: "spire-kubeconfig@" + clustername,
AuthInfos: authinfos,
}

kubeconfig, err := yaml.Marshal(clientConfig)

formattedKubeconfig := string(kubeconfig)

// kubeconfig := strings.TrimSpace(fmt.Sprintf(`
// apiVersion: v1
Expand Down

0 comments on commit a144351

Please sign in to comment.