[#6] Add config init subcommand
This change introduces logic for the config init subcommand, which generates an airshipctl configuration file with default values. The default values are extracted from constants and change when the source code is updated. Closes #6 Change-Id: I452e26bc5a924f0cdcd3153a9b124d23e2e5b1f0 Signed-off-by: Drew Walters <andrew.walters@att.com>
This commit is contained in:
parent
f8a9a471d3
commit
5d83122b17
1
.gitignore
vendored
1
.gitignore
vendored
@ -8,6 +8,7 @@ bin/
|
||||
|
||||
# Test binary, build wiith `go test -c`
|
||||
*.test
|
||||
*.example
|
||||
|
||||
# Output of the go coverage tool
|
||||
*.out
|
||||
|
@ -1,4 +1,4 @@
|
||||
/*l
|
||||
/*
|
||||
Copyright 2014 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -20,7 +20,6 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"opendev.org/airship/airshipctl/pkg/environment"
|
||||
"opendev.org/airship/airshipctl/pkg/errors"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -33,7 +32,14 @@ func NewCmdConfigInit(rootSettings *environment.AirshipCTLSettings) *cobra.Comma
|
||||
Use: "init",
|
||||
Short: configInitLong,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return errors.ErrNotImplemented{}
|
||||
c := rootSettings.Config()
|
||||
|
||||
err := c.PersistConfig()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -19,17 +19,15 @@ package config
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"opendev.org/airship/airshipctl/pkg/errors"
|
||||
"opendev.org/airship/airshipctl/testutil"
|
||||
)
|
||||
|
||||
func TestConfigInit(t *testing.T) {
|
||||
cmdTests := []*testutil.CmdTest{
|
||||
{
|
||||
Name: "config-init",
|
||||
CmdLine: "",
|
||||
Name: "config-init-help",
|
||||
CmdLine: "-h",
|
||||
Cmd: NewCmdConfigInit(nil),
|
||||
Error: errors.ErrNotImplemented{},
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
Error: Not implemented
|
||||
Generate initial configuration files for airshipctl
|
||||
|
||||
Usage:
|
||||
init [flags]
|
||||
|
||||
Flags:
|
||||
-h, --help help for init
|
||||
|
@ -82,7 +82,25 @@ func (c *Config) loadKubeConfig(kubeConfigPath string) error {
|
||||
// If I can read from the file, load from it
|
||||
var err error
|
||||
if _, err = os.Stat(kubeConfigPath); os.IsNotExist(err) {
|
||||
c.kubeConfig = clientcmdapi.NewConfig()
|
||||
// Default kubeconfig matching Airship target cluster
|
||||
c.kubeConfig = &clientcmdapi.Config{
|
||||
Clusters: map[string]*clientcmdapi.Cluster{
|
||||
AirshipDefaultContext: {
|
||||
Server: "https://172.17.0.1:6443",
|
||||
},
|
||||
},
|
||||
AuthInfos: map[string]*clientcmdapi.AuthInfo{
|
||||
"admin": {
|
||||
Username: "airship-admin",
|
||||
},
|
||||
},
|
||||
Contexts: map[string]*clientcmdapi.Context{
|
||||
AirshipDefaultContext: {
|
||||
Cluster: AirshipDefaultContext,
|
||||
AuthInfo: "admin",
|
||||
},
|
||||
},
|
||||
}
|
||||
return nil
|
||||
} else if err != nil {
|
||||
return err
|
||||
|
@ -27,6 +27,16 @@ const (
|
||||
|
||||
AirshipConfigEnv = "AIRSHIPCONFIG"
|
||||
AirshipKubeConfigEnv = "AIRSHIP_KUBECONFIG"
|
||||
|
||||
AirshipDefaultContext = "default"
|
||||
AirshipDefaultManifest = "default"
|
||||
AirshipDefaultManifestRepo = "treasuremap"
|
||||
AirshipDefaultManifestRepoLocation = "https://opendev.org/airship/" + AirshipDefaultManifestRepo
|
||||
|
||||
// Modules
|
||||
AirshipDefaultBootstrapImage = "quay.io/airshipit/isogen:latest"
|
||||
AirshipDefaultIsoURL = "http://localhost:8099/debian-custom.iso"
|
||||
AirshipDefaultRemoteType = "redfish"
|
||||
)
|
||||
|
||||
// Constants defining CLI flags
|
||||
|
@ -19,13 +19,48 @@ package config
|
||||
// NewConfig returns a newly initialized Config object
|
||||
func NewConfig() *Config {
|
||||
return &Config{
|
||||
Kind: AirshipConfigKind,
|
||||
APIVersion: AirshipConfigApiVersion,
|
||||
Clusters: make(map[string]*ClusterPurpose),
|
||||
Contexts: make(map[string]*Context),
|
||||
AuthInfos: make(map[string]*AuthInfo),
|
||||
Manifests: make(map[string]*Manifest),
|
||||
ModulesConfig: NewModules(),
|
||||
Kind: AirshipConfigKind,
|
||||
APIVersion: AirshipConfigApiVersion,
|
||||
Clusters: make(map[string]*ClusterPurpose),
|
||||
AuthInfos: make(map[string]*AuthInfo),
|
||||
Contexts: map[string]*Context{
|
||||
AirshipDefaultContext: {
|
||||
Manifest: AirshipDefaultManifest,
|
||||
},
|
||||
},
|
||||
Manifests: map[string]*Manifest{
|
||||
AirshipDefaultManifest: {
|
||||
Repository: &Repository{
|
||||
URLString: AirshipDefaultManifestRepoLocation,
|
||||
CheckoutOptions: &RepoCheckout{
|
||||
CommitHash: "master",
|
||||
Branch: "master",
|
||||
RemoteRef: "master",
|
||||
},
|
||||
},
|
||||
TargetPath: "/tmp/" + AirshipDefaultManifest,
|
||||
},
|
||||
},
|
||||
ModulesConfig: &Modules{
|
||||
BootstrapInfo: map[string]*Bootstrap{
|
||||
AirshipDefaultContext: {
|
||||
Container: &Container{
|
||||
Volume: "/srv/iso:/config",
|
||||
Image: AirshipDefaultBootstrapImage,
|
||||
ContainerRuntime: "docker",
|
||||
},
|
||||
Builder: &Builder{
|
||||
UserDataFileName: "user-data",
|
||||
NetworkConfigFileName: "network-config",
|
||||
OutputMetadataFileName: "output-metadata.yaml",
|
||||
},
|
||||
RemoteDirect: &RemoteDirect{
|
||||
RemoteType: AirshipDefaultRemoteType,
|
||||
IsoURL: AirshipDefaultIsoURL,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user