Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability for empty strings to be used as override, refactor clusterConfig #249

Draft
wants to merge 31 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
00023da
Save refactoring progress
George-Aeillo Jan 3, 2025
993e717
Save progress
George-Aeillo Jan 7, 2025
6ec82de
Save progress
George-Aeillo Jan 7, 2025
8bef657
Further save progress
George-Aeillo Jan 7, 2025
a5f0289
Save progress
George-Aeillo Jan 7, 2025
53480b3
Save progress on fixing pointer overrides and some command line parsing
George-Aeillo Jan 8, 2025
f68b38f
Save progress editing command line arguments
George-Aeillo Jan 8, 2025
092bb51
Save progress, fix further bugs, begin work on flag and override chec…
George-Aeillo Jan 8, 2025
d22d178
Save progress
George-Aeillo Jan 9, 2025
df1fb8c
Add check to prevent nil configFrom pointer dereference
George-Aeillo Jan 9, 2025
d7fe3e2
Comment out configfrom changes
George-Aeillo Jan 9, 2025
66ae731
Make changes to delete function
George-Aeillo Jan 9, 2025
33e0aee
Further update commands
George-Aeillo Jan 9, 2025
e8d77a3
Initial pass of revising overlaying
George-Aeillo Jan 10, 2025
982275d
Fix nil pointer errors in cluster join command
George-Aeillo Jan 13, 2025
1e58589
First pass of fixing parsing to work without a passed in cluster conf…
George-Aeillo Jan 13, 2025
600e87c
Add cluster name to debug message for deletion
George-Aeillo Jan 13, 2025
f898b1a
Further explain debug messages
George-Aeillo Jan 13, 2025
f90b653
Fix cad.kubeconfig to have the correct value
George-Aeillo Jan 13, 2025
712dd4e
Fix kubeConfig in the olvm provider
George-Aeillo Jan 13, 2025
32fcde0
Change logic to not allow cd and cdi to be defined in the same cluster
George-Aeillo Jan 14, 2025
3aa9cf5
Fix bug where control plane nodes were hardcoded to one
George-Aeillo Jan 14, 2025
14655a5
Fix bug where pointers are being checked before an ephemral cluster i…
George-Aeillo Jan 14, 2025
5410777
Fix debug output when ephemeral cluster is being started
George-Aeillo Jan 14, 2025
f46348a
Edit cluster defnition logic for olvm provider, along with fixing del…
George-Aeillo Jan 14, 2025
47a0dc5
Fix merge conflicts
George-Aeillo Jan 14, 2025
a5340aa
First pass of refactoring Dan's changes
George-Aeillo Jan 14, 2025
b9e71bf
Fix kubeconfig path for byo driver
George-Aeillo Jan 14, 2025
8187aef
First pass of ensuring catalog and applications have non-nil values
George-Aeillo Jan 15, 2025
bf191f9
Improve application merge functions, fix debug messages and other sma…
George-Aeillo Jan 15, 2025
d09499f
Remove unecessary change
George-Aeillo Jan 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions cmd/catalog/mirror/mirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func NewCmd() *cobra.Command {

// RunCmd runs the "ocne catalog mirror" command
func RunCmd(cmd *cobra.Command) error {
c, cc, err := cmdutil.GetFullConfig(&config, &clusterConfig, clusterConfigPath)
cc, err := cmdutil.GetFullConfig(&clusterConfig, clusterConfigPath)
if err != nil {
err = errors.New("Configuration error: " + err.Error())
return err
Expand All @@ -125,7 +125,6 @@ func RunCmd(cmd *cobra.Command) error {
DestinationURI: destination,
ConfigURI: clusterConfigPath,
Push: push,
Config: c,
ClusterConfig: cc,
DefaultRegistry: defaultRegistry,
Download: download,
Expand Down
55 changes: 38 additions & 17 deletions cmd/cluster/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ const (
flagConfigHelp = "The path to a configuration file that contains the definition of the cluster to delete. If this value is not provided, it will destroy the small cluster that was generated by `ocne` `start` when run with no configuration file"
)

var config types.Config
var clusterConfig types.ClusterConfig
var clusterConfigPath string

var options delete2.DeleteOptions = delete2.DeleteOptions{
Config: &types.Config{},
ClusterConfig: &types.ClusterConfig{},
}

func NewCmd() *cobra.Command {
cmd := &cobra.Command{
Use: CommandName,
Expand All @@ -48,25 +51,24 @@ func NewCmd() *cobra.Command {
cmd.Example = helpExample
cmdutil.SilenceUsage(cmd)

cmd.Flags().StringVarP(&config.KubeConfig, constants.FlagKubeconfig, constants.FlagKubeconfigShort, "", constants.FlagKubeconfigHelp)
cmd.Flags().StringVarP(&options.KubeConfigPath, constants.FlagKubeconfig, constants.FlagKubeconfigShort, "", constants.FlagKubeconfigHelp)
cmd.Flags().StringVarP(&clusterConfigPath, flagConfig, flagConfigShort, "", flagConfigHelp)
cmd.Flags().StringVarP(&config.Providers.Libvirt.SessionURI, constants.FlagSshURI, constants.FlagSshURIShort, "", constants.FlagSshURIHelp)
cmd.Flags().StringVarP(&clusterConfig.Name, constants.FlagClusterName, constants.FlagClusterNameShort, "", constants.FlagClusterNameHelp)
cmd.Flags().StringVarP(&clusterConfig.Provider, constants.FlagProviderName, constants.FlagProviderNameShort, "", constants.FlagProviderNameHelp)
cmd.Flags().StringVarP(&options.SessionURI, constants.FlagSshURI, constants.FlagSshURIShort, "", constants.FlagSshURIHelp)
cmd.Flags().StringVarP(&options.Name, constants.FlagClusterName, constants.FlagClusterNameShort, "", constants.FlagClusterNameHelp)
cmd.Flags().StringVarP(&options.Provider, constants.FlagProviderName, constants.FlagProviderNameShort, "", constants.FlagProviderNameHelp)

return cmd
}

// RunCmd runs the "ocne cluster rm" command
func RunCmd(cmd *cobra.Command) error {
populateConfigurationFromCommandLine(&options)
clusterCache, err := cache.GetCache()
if err != nil {
return err
}

var c *types.Config
var cc *types.ClusterConfig
clusterName := clusterConfig.Name
clusterName := options.ClusterConfig.Name

// If a cluster config file has been passed, load it up.
// This is done to get the cluster name.
Expand All @@ -79,30 +81,49 @@ func RunCmd(cmd *cobra.Command) error {
clusterName = cc.Name
}

cached := clusterCache.Get(clusterName)
var cached *cache.Cluster
if clusterName != nil {
cached = clusterCache.Get(*clusterName)
}

// If the cluster does not exist, fall back to the CLI options.
// This is a bail-out to make sure all the needful can be done in
// case of some poorly timed error.
if cached == nil {
c, cc, err = cmdutil.GetFullConfig(&config, &clusterConfig, clusterConfigPath)
cc, err = cmdutil.GetFullConfig(options.ClusterConfig, clusterConfigPath)
if err != nil {
return err
}
} else {
c, cc, err = cmdutil.GetFullConfig(&config, &cached.ClusterConfig, "")
cc, err = cmdutil.GetFullConfig(&cached.ClusterConfig, "")
if err != nil {
return err
}
}

if cc.Name == "" {
cc.Name = "ocne"
if *cc.Name == "" {
*cc.Name = "ocne"
}
if cc.Provider == "" {
cc.Provider = pkgconst.ProviderTypeLibvirt
if *cc.Provider == "" {
*cc.Provider = pkgconst.ProviderTypeLibvirt
}

err = delete2.Delete(c, cc)
err = delete2.Delete(cc)
return err
}

func populateConfigurationFromCommandLine(options *delete2.DeleteOptions) {
if options.Name != "" {
options.ClusterConfig.Name = &options.Name
}
if options.KubeConfigPath != "" {
options.ClusterConfig.KubeConfig = &options.KubeConfigPath
}
if options.SessionURI != "" {
options.ClusterConfig.Providers.Libvirt.SessionURI = &options.SessionURI
}
if options.Provider != "" {
options.ClusterConfig.Provider = &options.Provider
}

}
17 changes: 11 additions & 6 deletions cmd/cluster/join/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func NewCmd() *cobra.Command {
cmd.Flags().StringVarP(&clusterConfigPath, constants.FlagConfig, constants.FlagConfigShort, "", constants.FlagConfigHelp)
cmd.Flags().StringVarP(&options.KubeConfigPath, constants.FlagKubeconfig, constants.FlagKubeconfigShort, "", constants.FlagKubeconfigHelp)
cmd.Flags().StringVarP(&options.DestKubeConfigPath, flagDestination, flagDestinationShort, "", flagDestinationHelp)
cmd.Flags().StringVarP(&options.ClusterConfig.Provider, constants.FlagProviderName, constants.FlagProviderNameShort, "libvirt", constants.FlagProviderNameHelp)
cmd.Flags().StringVarP(&options.Provider, constants.FlagProviderName, constants.FlagProviderNameShort, "libvirt", constants.FlagProviderNameHelp)
cmd.Flags().StringVarP(&options.Node, flagNode, flagNodeShort, "", flagNodeHelp)
cmd.Flags().IntVarP(&options.ControlPlaneNodes, flagControlPlaneNodes, flagControlPlaneNodesShort, 0, flagControlPlaneNodesHelp)
cmd.Flags().IntVarP(&options.WorkerNodes, flagWorkerNodes, flagWorkerNodesShort, 0, flagWorkerNodesHelp)
Expand All @@ -86,7 +86,7 @@ func NewCmd() *cobra.Command {

// RunCmd runs the "ocne cluster join" command
func RunCmd(cmd *cobra.Command) error {
if err := validateOptions(&options, cmd); err != nil {
if err := validateOptions(&options); err != nil {
return err
}
clusterCache, err := cache.GetCache()
Expand All @@ -102,11 +102,11 @@ func RunCmd(cmd *cobra.Command) error {
return err
}
// Make sure the tag matches Kubeversion, unless it is overridden
if options.ClusterConfig.OsTag == "" {
if options.ClusterConfig.OsTag == nil {
options.ClusterConfig.OsTag = options.ClusterConfig.KubeVersion
}

clusterName = options.ClusterConfig.Name
clusterName = *options.ClusterConfig.Name
}

cached := clusterCache.Get(clusterName)
Expand All @@ -115,7 +115,7 @@ func RunCmd(cmd *cobra.Command) error {
// This is a bail-out to make sure all the needful can be done in
// case of some poorly timed error.
if cached == nil {
options.Config, options.ClusterConfig, err = cmdutil.GetFullConfig(options.Config, options.ClusterConfig, clusterConfigPath)
options.ClusterConfig, err = cmdutil.GetFullConfig(options.ClusterConfig, clusterConfigPath)
if err != nil {
return err
}
Expand Down Expand Up @@ -146,7 +146,12 @@ func RunCmd(cmd *cobra.Command) error {
return cmdjoin.Join(&options)
}

func validateOptions(options *cmdjoin.JoinOptions, cmd *cobra.Command) error {
func validateOptions(options *cmdjoin.JoinOptions) error {
if options.Provider != "" {
options.ClusterConfig.Provider = &options.Provider
}
// This is a workaround for using the Cobra CLI to populate a structure that has fields that are pointers

if options.DestKubeConfigPath != "" || options.Node != "" {
// this is the case where we are joining an existing node to another cluster, both of these options must be specified
if options.DestKubeConfigPath == "" {
Expand Down
10 changes: 3 additions & 7 deletions cmd/cluster/stage/stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ package stage
import (
"fmt"

"github.com/spf13/cobra"
"github.com/oracle-cne/ocne/cmd/constants"
"github.com/oracle-cne/ocne/pkg/cluster/cache"
"github.com/oracle-cne/ocne/pkg/cmdutil"
"github.com/oracle-cne/ocne/pkg/commands/cluster/stage"
"github.com/oracle-cne/ocne/pkg/config/types"
"github.com/spf13/cobra"
)

const (
Expand Down Expand Up @@ -87,28 +87,24 @@ func RunCmd(cmd *cobra.Command) error {
return fmt.Errorf("Cluster %s is not in the cache", clusterName)
}

c := &types.Config{}
cc := &types.ClusterConfig{}
c, cc, err = cmdutil.GetFullConfig(c, &cached.ClusterConfig, clusterConfigPath)
cc, err = cmdutil.GetFullConfig(&cached.ClusterConfig, clusterConfigPath)
if err != nil {
return err
}

options.ClusterConfig = cc
options.Config = c
}

if clusterConfigPath != "" {
c := &types.Config{}
cc := &types.ClusterConfig{}

c, cc, err := cmdutil.GetFullConfig(c, cc, clusterConfigPath)
cc, err := cmdutil.GetFullConfig(cc, clusterConfigPath)
if err != nil {
return err
}

options.ClusterConfig = cc
options.Config = c
}

err := stage.Stage(options)
Expand Down
103 changes: 69 additions & 34 deletions cmd/cluster/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ ocne cluster start --config ~/example-path/config-file --control-plane-nodes 2 -
`
)

var config types.Config
var clusterConfig types.ClusterConfig
var options start.StartOptions = start.StartOptions{
Config: &types.Config{},
ClusterConfig: &types.ClusterConfig{},
}
var clusterConfigPath string

const (
Expand Down Expand Up @@ -58,66 +60,99 @@ func NewCmd() *cobra.Command {
cmd.Example = helpExample
cmdutil.SilenceUsage(cmd)

cmd.Flags().StringVarP(&config.KubeConfig, constants.FlagKubeconfig, constants.FlagKubeconfigShort, "", constants.FlagKubeconfigHelp)
cmd.Flags().StringVarP(&options.KubeConfigPath, constants.FlagKubeconfig, constants.FlagKubeconfigShort, "", constants.FlagKubeconfigHelp)
cmd.Flags().StringVarP(&clusterConfigPath, constants.FlagConfig, constants.FlagConfigShort, "", constants.FlagConfigHelp)
cmd.Flags().Uint16VarP(&clusterConfig.ControlPlaneNodes, flagControlPlaneNodes, flagControlPlaneNodesShort, 0, flagControlPlaneNodesHelp)
cmd.Flags().Uint16VarP(&clusterConfig.WorkerNodes, flagWorkerNodes, flagWorkerNodesShort, 0, flagWorkerNodesHelp)
cmd.Flags().StringVarP(&config.Providers.Libvirt.SessionURI, constants.FlagSshURI, constants.FlagSshURIShort, "", constants.FlagSshURIHelp)
cmd.Flags().StringVarP(&config.Providers.Libvirt.SshKey, constants.FlagSshKey, constants.FlagSshKeyShort, "", constants.FlagSshKeyHelp)
cmd.Flags().StringVarP(&config.BootVolumeContainerImage, constants.FlagBootVolumeContainerImage, constants.FlagBootVolumeContainerImageShort, "", constants.FlagBootVolumeContainerImageHelp)
cmd.Flags().StringVarP(&clusterConfig.Name, constants.FlagClusterName, constants.FlagClusterNameShort, "", constants.FlagClusterNameHelp)
cmd.Flags().StringVarP(&clusterConfig.Provider, constants.FlagProviderName, constants.FlagProviderNameShort, "", constants.FlagProviderNameHelp)
cmd.Flags().StringVarP(&config.AutoStartUI, constants.FlagAutoStartUIName, constants.FlagAutoStartUINameShort, "", constants.FlagAutoStartUIHelp)
cmd.Flags().StringVarP(&clusterConfig.KubeVersion, constants.FlagVersionName, constants.FlagVersionShort, "", constants.FlagKubernetesVersionHelp)
cmd.Flags().StringVar(&clusterConfig.VirtualIp, flagVirtualIP, "", flagVirtualIPHelp)
cmd.Flags().StringVar(&clusterConfig.LoadBalancer, flagLoadBalancer, "", flagLoadBalancerHelp)
cmd.Flags().Uint16VarP(&options.ControlPlaneNodes, flagControlPlaneNodes, flagControlPlaneNodesShort, 0, flagControlPlaneNodesHelp)
cmd.Flags().Uint16VarP(&options.WorkerNodes, flagWorkerNodes, flagWorkerNodesShort, 0, flagWorkerNodesHelp)
cmd.Flags().StringVarP(&options.SessionURI, constants.FlagSshURI, constants.FlagSshURIShort, "", constants.FlagSshURIHelp)
cmd.Flags().StringVarP(&options.SSHKey, constants.FlagSshKey, constants.FlagSshKeyShort, "", constants.FlagSshKeyHelp)
cmd.Flags().StringVarP(&options.BootVolumeContainerImage, constants.FlagBootVolumeContainerImage, constants.FlagBootVolumeContainerImageShort, "", constants.FlagBootVolumeContainerImageHelp)
cmd.Flags().StringVarP(&options.Name, constants.FlagClusterName, constants.FlagClusterNameShort, "", constants.FlagClusterNameHelp)
cmd.Flags().StringVarP(&options.Provider, constants.FlagProviderName, constants.FlagProviderNameShort, "", constants.FlagProviderNameHelp)
cmd.Flags().StringVarP(&options.AutoStartUI, constants.FlagAutoStartUIName, constants.FlagAutoStartUINameShort, "", constants.FlagAutoStartUIHelp)
cmd.Flags().StringVarP(&options.KubeVersion, constants.FlagVersionName, constants.FlagVersionShort, "", constants.FlagKubernetesVersionHelp)
cmd.Flags().StringVar(&options.VirtualIp, flagVirtualIP, "", flagVirtualIPHelp)
cmd.Flags().StringVar(&options.LoadBalancer, flagLoadBalancer, "", flagLoadBalancerHelp)
cmd.MarkFlagsMutuallyExclusive(flagVirtualIP, flagLoadBalancer)

return cmd
}

// RunCmd runs the "ocne cluster start" command
func RunCmd(cmd *cobra.Command) error {
c, cc, err := cmdutil.GetFullConfig(&config, &clusterConfig, clusterConfigPath)
populateConfigurationFromCommandLine(&options)
cc, err := cmdutil.GetFullConfig(options.ClusterConfig, clusterConfigPath)
if err != nil {
return err
}
if cc.Name == "" {
cc.Name = "ocne"
if *cc.Name == "" {
*cc.Name = "ocne"
}
if cc.Provider == "" {
cc.Provider = pkgconst.ProviderTypeLibvirt
if *cc.Provider == "" {
*cc.Provider = pkgconst.ProviderTypeLibvirt
}
if cc.ControlPlaneNodes == 0 {
cc.ControlPlaneNodes = 1
if *cc.ControlPlaneNodes == 0 {
*cc.ControlPlaneNodes = 1
}
imageTransport := alltransports.TransportFromImageName(cc.BootVolumeContainerImage)
imageTransport := alltransports.TransportFromImageName(*cc.BootVolumeContainerImage)
if imageTransport == nil {
// No transport protocol detected. Adding docker transport protocol as default.
cc.BootVolumeContainerImage = "docker://" + cc.BootVolumeContainerImage
*cc.BootVolumeContainerImage = "docker://" + *cc.BootVolumeContainerImage
}

// Append the version to the boot volume container image registry path specified, if it does not already exist
cc.BootVolumeContainerImage, err = cmdutil.EnsureBootImageVersion(cc.KubeVersion, cc.BootVolumeContainerImage)
*cc.BootVolumeContainerImage, err = cmdutil.EnsureBootImageVersion(*cc.KubeVersion, *cc.BootVolumeContainerImage)
if err != nil {
return err
}

// if the user has not overridden the osTag and the requested k8s version is not the default, make the osTag
// match the k8s version
if cc.OsTag == pkgconst.KubeVersion && cc.KubeVersion != pkgconst.KubeVersion {
if *cc.OsTag == pkgconst.KubeVersion && *cc.KubeVersion != pkgconst.KubeVersion {
cc.OsTag = cc.KubeVersion
}

// if the provider is libvirt, update fields in the config otherwise the changes to the clusterConfig fields
// will be overwritten
if cc.Provider == pkgconst.ProviderTypeLibvirt {
c.BootVolumeContainerImage = cc.BootVolumeContainerImage
c.KubeVersion = cc.KubeVersion
c.OsTag = cc.OsTag
}

_, err = start.Start(c, cc)
_, err = start.Start(cc)

return err
}

func populateConfigurationFromCommandLine(options *start.StartOptions) {
if options.Name != "" {
options.ClusterConfig.Name = &options.Name
}
if options.KubeConfigPath != "" {
options.ClusterConfig.KubeConfig = &options.KubeConfigPath
}
if options.SessionURI != "" {
options.ClusterConfig.Providers.Libvirt.SessionURI = &options.SessionURI
}
if options.Provider != "" {
options.ClusterConfig.Provider = &options.Provider
}
if options.SSHKey != "" {
options.ClusterConfig.Providers.Libvirt.SshKey = &options.SSHKey
}
if options.BootVolumeContainerImage != "" {
options.ClusterConfig.BootVolumeContainerImage = &options.BootVolumeContainerImage
}
if options.AutoStartUI != "" {
options.ClusterConfig.AutoStartUI = &options.AutoStartUI
}
if options.ControlPlaneNodes != uint16(0) {
options.ClusterConfig.ControlPlaneNodes = &options.ControlPlaneNodes
}
if options.WorkerNodes != uint16(0) {
options.ClusterConfig.WorkerNodes = &options.WorkerNodes
}
if options.KubeVersion != "" {
options.ClusterConfig.KubeVersion = &options.KubeVersion
}
if options.VirtualIp != "" {
options.ClusterConfig.VirtualIp = &options.VirtualIp
}
if options.LoadBalancer != "" {
options.ClusterConfig.LoadBalancer = &options.LoadBalancer
}

}
Loading