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 430f6ae commit 3ca41fe
Showing 1 changed file with 60 additions and 20 deletions.
80 changes: 60 additions & 20 deletions controllers/pkg/reconcilers/spire-bootstrap/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ 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 Down Expand Up @@ -368,25 +369,64 @@ func (r *reconciler) createKubeconfigConfigMap(ctx context.Context, clientset *k
}
caCert := configMap.Data["ca.crt"]

kubeconfig := strings.TrimSpace(fmt.Sprintf(`
apiVersion: v1
kind: Config
clusters:
- cluster:
certificate-authority-data: %s
server: %s
name: regional
contexts:
- context:
cluster: %s
namespace: spire
user: spire-kubeconfig
current-context: spire-kubeconfig@regional
users:
- name: spire-kubeconfig
user:
token: %s
`, base64.StdEncoding.EncodeToString([]byte(caCert)), clientset.RESTClient().Get().URL().String(), clustername, token))
kubeconfig := map[string]interface{}{
"apiVersion": "v1",
"kind": "Config",
"clusters": []map[string]interface{}{
{
"cluster": map[string]string{
"certificate-authority-data": base64.StdEncoding.EncodeToString([]byte(caCert)),
"server": clientset.RESTClient().Get().URL().String(),
},
"name": "regional",
},
},
"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,
},
},
},
}

yamlData, err := yaml.Marshal(kubeconfig)
if err != nil {
// Handle error
}

formattedKubeconfig := string(yamlData)

// kubeconfig := strings.TrimSpace(fmt.Sprintf(`
// apiVersion: v1
// kind: Config
// clusters:
// - cluster:
// certificate-authority-data: %s
// server: %s
// name: regional
// contexts:
// - context:
// cluster: %s
// namespace: spire
// user: spire-kubeconfig
// current-context: spire-kubeconfig@regional
// users:
// - name: spire-kubeconfig
// user:
// token: %s
// `, base64.StdEncoding.EncodeToString([]byte(caCert)), clientset.RESTClient().Get().URL().String(), clustername, token))

// Generate a unique key for the new kubeconfig
newConfigKey := fmt.Sprintf("kubeconfig-%s", clustername)
Expand All @@ -395,7 +435,7 @@ func (r *reconciler) createKubeconfigConfigMap(ctx context.Context, clientset *k
if restrictedKC.Data == nil {
restrictedKC.Data = make(map[string]string)
}
restrictedKC.Data[newConfigKey] = kubeconfig
restrictedKC.Data[newConfigKey] = formattedKubeconfig

// _, err = clientset.CoreV1().ConfigMaps("spire").Create(context.TODO(), kubeconfigCM, metav1.CreateOptions{})
err = r.Update(ctx, restrictedKC)
Expand Down

0 comments on commit 3ca41fe

Please sign in to comment.