Skip to content

Commit

Permalink
backend: headlamp.go: Reformat customNameToExtenstions to work with h…
Browse files Browse the repository at this point in the history
…eadlamp_info changes

Signed-off-by: Vincent T <[email protected]>
  • Loading branch information
vyncent-t committed Jan 22, 2025
1 parent c143340 commit 0dad606
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
32 changes: 23 additions & 9 deletions backend/cmd/headlamp.go
Original file line number Diff line number Diff line change
Expand Up @@ -1557,20 +1557,34 @@ func customNameToExtenstions(config *api.Config, contextName, newClusterName, pa
return err
}

// Create a CustomObject with CustomName field
customObj := &kubeconfig.CustomObject{
TypeMeta: v1.TypeMeta{},
ObjectMeta: v1.ObjectMeta{},
CustomName: newClusterName,
}
headlampInfo := contextConfig.Extensions["headlamp_info"]

// Assign the CustomObject to the Extensions map
contextConfig.Extensions["headlamp_info"] = customObj
if headlampInfo != nil {
existingObj, err := MarshalCustomObject(headlampInfo, contextName)
originalName := existingObj.OriginalName

if err == nil {
customObj := &kubeconfig.CustomObject{
TypeMeta: v1.TypeMeta{},
ObjectMeta: v1.ObjectMeta{},
OriginalName: originalName,
CustomName: newClusterName,
}
customObj.OriginalName = existingObj.OriginalName

// Assign the CustomObject to the Extensions map
contextConfig.Extensions["headlamp_info"] = customObj
} else {
logger.Log(logger.LevelError, map[string]string{"cluster": contextName},
err, "ERROR setting customName - failure to marshaling custom object")

return err
}
}

if err := clientcmd.WriteToFile(*config, path); err != nil {
logger.Log(logger.LevelError, map[string]string{"cluster": contextName},
err, "writing kubeconfig file")

return err
}

Expand Down
5 changes: 5 additions & 0 deletions backend/pkg/kubeconfig/kubeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,14 @@ type OidcConfig struct {

// CustomObject represents the custom object that holds the HeadlampInfo regarding custom name.
type CustomObject struct {
// ???
metav1.TypeMeta
// ???
metav1.ObjectMeta
// CustomName is the name the cluster is renamed to.
CustomName string `json:"customName"`
// originalName is the name the cluster was created with.
OriginalName string `json:"originalName"`
}

// DeepCopyObject returns a copy of the CustomObject.
Expand Down

0 comments on commit 0dad606

Please sign in to comment.