mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-10-01 01:36:09 -04:00
cli: add missing flag to miniConstellation (#1374)
* Add missing flag to miniConstellation * Add config merger to miniConstellation * Soft fail if config can not be merged * Remove config flattening * Release spinner stop lock when stopping finished --------- Signed-off-by: Daniel Weiße <dw@edgeless.systems> Co-authored-by: Nils Hanke <nils.hanke@outlook.com>
This commit is contained in:
parent
ebf7dd8842
commit
446b77828b
@ -44,7 +44,6 @@ import (
|
|||||||
"google.golang.org/grpc/connectivity"
|
"google.golang.org/grpc/connectivity"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/client-go/tools/clientcmd"
|
"k8s.io/client-go/tools/clientcmd"
|
||||||
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
|
|
||||||
clientcodec "k8s.io/client-go/tools/clientcmd/api/latest"
|
clientcodec "k8s.io/client-go/tools/clientcmd/api/latest"
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
)
|
)
|
||||||
@ -292,9 +291,11 @@ func (i *initCmd) writeOutput(
|
|||||||
|
|
||||||
if mergeConfig {
|
if mergeConfig {
|
||||||
if err := i.merger.mergeConfigs(constants.AdminConfFilename, fileHandler); err != nil {
|
if err := i.merger.mergeConfigs(constants.AdminConfFilename, fileHandler); err != nil {
|
||||||
return fmt.Errorf("merging kubeconfig: %w", err)
|
writeRow(tw, "Failed to automatically merge kubeconfig", err.Error())
|
||||||
|
mergeConfig = false // Set to false so we don't print the wrong message below.
|
||||||
|
} else {
|
||||||
|
writeRow(tw, "Kubernetes configuration merged with default config", "")
|
||||||
}
|
}
|
||||||
writeRow(tw, "Kubernetes configuration merged with default config", "")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
idFile.OwnerID = ownerID
|
idFile.OwnerID = ownerID
|
||||||
@ -478,19 +479,16 @@ func (c *kubeconfigMerger) mergeConfigs(configPath string, fileHandler file.Hand
|
|||||||
|
|
||||||
loadingRules := clientcmd.NewDefaultClientConfigLoadingRules()
|
loadingRules := clientcmd.NewDefaultClientConfigLoadingRules()
|
||||||
loadingRules.Precedence = []string{
|
loadingRules.Precedence = []string{
|
||||||
configPath, // load our config first so it takes precedence
|
clientcmd.RecommendedHomeFile,
|
||||||
clientcmd.RecommendedHomeFile, // then load the default config
|
configPath, // our config should overwrite the default config
|
||||||
}
|
}
|
||||||
c.log.Debugf("Kubeconfig file loading precedence: %v", loadingRules.Precedence)
|
c.log.Debugf("Kubeconfig file loading precedence: %v", loadingRules.Precedence)
|
||||||
|
|
||||||
// merge and flatten the kubeconfigs
|
// merge the kubeconfigs
|
||||||
cfg, err := loadingRules.Load()
|
cfg, err := loadingRules.Load()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("loading merged kubeconfig: %w", err)
|
return fmt.Errorf("loading merged kubeconfig: %w", err)
|
||||||
}
|
}
|
||||||
if err := clientcmdapi.FlattenConfig(cfg); err != nil {
|
|
||||||
return fmt.Errorf("flattening merged kubeconfig: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set the current context to the cluster we just created
|
// Set the current context to the cluster we just created
|
||||||
cfg.CurrentContext = constellConfig.CurrentContext
|
cfg.CurrentContext = constellConfig.CurrentContext
|
||||||
|
@ -42,6 +42,7 @@ func newMiniUpCmd() *cobra.Command {
|
|||||||
|
|
||||||
// override global flag so we don't have a default value for the config
|
// override global flag so we don't have a default value for the config
|
||||||
cmd.Flags().String("config", "", "path to the configuration file to use for the cluster")
|
cmd.Flags().String("config", "", "path to the configuration file to use for the cluster")
|
||||||
|
cmd.Flags().Bool("merge-kubeconfig", true, "merge Constellation kubeconfig file with default kubeconfig file in $HOME/.kube/config")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
@ -264,7 +265,7 @@ func (m *miniUpCmd) initializeMiniCluster(cmd *cobra.Command, fileHandler file.H
|
|||||||
}
|
}
|
||||||
m.log.Debugf("Created new logger")
|
m.log.Debugf("Created new logger")
|
||||||
defer log.Sync()
|
defer log.Sync()
|
||||||
i := &initCmd{log: log}
|
i := &initCmd{log: log, merger: &kubeconfigMerger{log: log}}
|
||||||
if err := i.initialize(cmd, newDialer, fileHandler, license.NewClient(), spinner); err != nil {
|
if err := i.initialize(cmd, newDialer, fileHandler, license.NewClient(), spinner); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -84,6 +84,7 @@ func (s *spinner) Start(text string, showDots bool) {
|
|||||||
func (s *spinner) Stop() {
|
func (s *spinner) Stop() {
|
||||||
s.stop.Store(true)
|
s.stop.Store(true)
|
||||||
s.wg.Wait()
|
s.wg.Wait()
|
||||||
|
s.stop.Store(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write stops the spinner and writes the given bytes to the underlying writer.
|
// Write stops the spinner and writes the given bytes to the underlying writer.
|
||||||
|
Loading…
Reference in New Issue
Block a user