Skip to content

Commit

Permalink
feat: added --distro-patches flag (#511)
Browse files Browse the repository at this point in the history
* feat: added --distro-patches flag

* fix: switch from error to warn when not finding a version in custom patches location
  • Loading branch information
Al-Pragliola authored and Alessio Pragliola committed May 3, 2024
1 parent f1b80ab commit 017cfdc
Show file tree
Hide file tree
Showing 12 changed files with 327 additions and 147 deletions.
153 changes: 91 additions & 62 deletions cmd/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,32 @@ type Timeouts struct {
PodRunningCheckTimeout int
}

type ClusterSkipsCmdFlags struct {
SkipVpn bool
SkipDepsDownload bool
SkipDepsValidation bool
SkipNodesUpgrade bool
}

type ClusterCmdFlags struct {
Timeouts
Debug bool
FuryctlPath string
DistroLocation string
Phase string
StartFrom string
BinPath string
SkipVpn bool
VpnAutoConnect bool
DryRun bool
SkipDepsDownload bool
SkipDepsValidation bool
SkipNodesUpgrade bool
NoTTY bool
GitProtocol git.Protocol
Force []string
Outdir string
Upgrade bool
UpgradePathLocation string
UpgradeNode string
Debug bool
FuryctlPath string
DistroLocation string
Phase string
StartFrom string
BinPath string
VpnAutoConnect bool
DryRun bool
NoTTY bool
GitProtocol git.Protocol
Force []string
Outdir string
Upgrade bool
UpgradePathLocation string
UpgradeNode string
DistroPatchesLocation string
ClusterSkipsCmdFlags
}

func NewApplyCommand(tracker *analytics.Tracker) *cobra.Command {
Expand Down Expand Up @@ -107,9 +112,9 @@ func NewApplyCommand(tracker *analytics.Tracker) *cobra.Command {
depsvl := dependencies.NewValidator(executor, flags.BinPath, flags.FuryctlPath, flags.VpnAutoConnect)

if flags.DistroLocation == "" {
distrodl = distribution.NewCachingDownloader(client, outDir, flags.GitProtocol)
distrodl = distribution.NewCachingDownloader(client, outDir, flags.GitProtocol, flags.DistroPatchesLocation)
} else {
distrodl = distribution.NewDownloader(client, flags.GitProtocol)
distrodl = distribution.NewDownloader(client, flags.GitProtocol, flags.DistroPatchesLocation)
}

// Init packages.
Expand Down Expand Up @@ -240,7 +245,41 @@ func NewApplyCommand(tracker *analytics.Tracker) *cobra.Command {
return cmd
}

func getSkipsClusterCmdFlags(cmd *cobra.Command, tracker *analytics.Tracker, cmdEvent analytics.Event) (ClusterSkipsCmdFlags, error) {
skipDepsDownload, err := cmdutil.BoolFlag(cmd, "skip-deps-download", tracker, cmdEvent)
if err != nil {
return ClusterSkipsCmdFlags{}, fmt.Errorf(WrappedErrMessage, ErrParsingFlag, "skip-deps-download")
}

skipDepsValidation, err := cmdutil.BoolFlag(cmd, "skip-deps-validation", tracker, cmdEvent)
if err != nil {
return ClusterSkipsCmdFlags{}, fmt.Errorf(WrappedErrMessage, ErrParsingFlag, "skip-deps-validation")
}

skipNodesUpgrade, err := cmdutil.BoolFlag(cmd, "skip-nodes-upgrade", tracker, cmdEvent)
if err != nil {
return ClusterSkipsCmdFlags{}, fmt.Errorf(WrappedErrMessage, ErrParsingFlag, "skip-nodes-upgrade")
}

skipVpn, err := cmdutil.BoolFlag(cmd, "skip-vpn-confirmation", tracker, cmdEvent)
if err != nil {
return ClusterSkipsCmdFlags{}, fmt.Errorf(WrappedErrMessage, ErrParsingFlag, "skip-vpn-confirmation")
}

return ClusterSkipsCmdFlags{
SkipVpn: skipVpn,
SkipDepsDownload: skipDepsDownload,
SkipDepsValidation: skipDepsValidation,
SkipNodesUpgrade: skipNodesUpgrade,
}, nil
}

func getCreateClusterCmdFlags(cmd *cobra.Command, tracker *analytics.Tracker, cmdEvent analytics.Event) (ClusterCmdFlags, error) {
skips, err := getSkipsClusterCmdFlags(cmd, tracker, cmdEvent)
if err != nil {
return ClusterCmdFlags{}, err
}

debug, err := cmdutil.BoolFlag(cmd, "debug", tracker, cmdEvent)
if err != nil {
return ClusterCmdFlags{}, fmt.Errorf(WrappedErrMessage, ErrParsingFlag, "debug")
Expand Down Expand Up @@ -286,17 +325,12 @@ func getCreateClusterCmdFlags(cmd *cobra.Command, tracker *analytics.Tracker, cm

binPath := cmdutil.StringFlagOptional(cmd, "bin-path")

skipVpn, err := cmdutil.BoolFlag(cmd, "skip-vpn-confirmation", tracker, cmdEvent)
if err != nil {
return ClusterCmdFlags{}, fmt.Errorf(WrappedErrMessage, ErrParsingFlag, "skip-vpn-confirmation")
}

vpnAutoConnect, err := cmdutil.BoolFlag(cmd, "vpn-auto-connect", tracker, cmdEvent)
if err != nil {
return ClusterCmdFlags{}, fmt.Errorf(WrappedErrMessage, ErrParsingFlag, "vpn-auto-connect")
}

if skipVpn && vpnAutoConnect {
if skips.SkipVpn && vpnAutoConnect {
return ClusterCmdFlags{}, fmt.Errorf(
"%w: %s: cannot use together with skip-vpn flag",
ErrParsingFlag,
Expand All @@ -319,21 +353,6 @@ func getCreateClusterCmdFlags(cmd *cobra.Command, tracker *analytics.Tracker, cm
return ClusterCmdFlags{}, fmt.Errorf(WrappedErrMessage, ErrParsingFlag, "force")
}

skipDepsDownload, err := cmdutil.BoolFlag(cmd, "skip-deps-download", tracker, cmdEvent)
if err != nil {
return ClusterCmdFlags{}, fmt.Errorf(WrappedErrMessage, ErrParsingFlag, "skip-deps-download")
}

skipDepsValidation, err := cmdutil.BoolFlag(cmd, "skip-deps-validation", tracker, cmdEvent)
if err != nil {
return ClusterCmdFlags{}, fmt.Errorf(WrappedErrMessage, ErrParsingFlag, "skip-deps-validation")
}

skipNodesUpgrade, err := cmdutil.BoolFlag(cmd, "skip-nodes-upgrade", tracker, cmdEvent)
if err != nil {
return ClusterCmdFlags{}, fmt.Errorf(WrappedErrMessage, ErrParsingFlag, "skip-nodes-upgrade")
}

gitProtocol, err := cmdutil.StringFlag(cmd, "git-protocol", tracker, cmdEvent)
if err != nil {
return ClusterCmdFlags{}, fmt.Errorf(WrappedErrMessage, ErrParsingFlag, "git-protocol")
Expand Down Expand Up @@ -382,30 +401,33 @@ func getCreateClusterCmdFlags(cmd *cobra.Command, tracker *analytics.Tracker, cm
)
}

distroPatchesLocation, err := cmdutil.StringFlag(cmd, "distro-patches", tracker, cmdEvent)
if err != nil {
return ClusterCmdFlags{}, fmt.Errorf("%w: %s", ErrParsingFlag, "distro-patches")
}

return ClusterCmdFlags{
Debug: debug,
FuryctlPath: furyctlPath,
DistroLocation: distroLocation,
Phase: phase,
StartFrom: startFrom,
BinPath: binPath,
SkipVpn: skipVpn,
VpnAutoConnect: vpnAutoConnect,
DryRun: dryRun,
SkipDepsDownload: skipDepsDownload,
SkipDepsValidation: skipDepsValidation,
SkipNodesUpgrade: skipNodesUpgrade,
NoTTY: noTTY,
Force: force,
GitProtocol: typedGitProtocol,
Debug: debug,
FuryctlPath: furyctlPath,
DistroLocation: distroLocation,
Phase: phase,
StartFrom: startFrom,
BinPath: binPath,
VpnAutoConnect: vpnAutoConnect,
DryRun: dryRun,
NoTTY: noTTY,
Force: force,
GitProtocol: typedGitProtocol,
Timeouts: Timeouts{
ProcessTimeout: timeout,
PodRunningCheckTimeout: podRunningCheckTimeout,
},
Outdir: outdir,
Upgrade: upgrade,
UpgradePathLocation: upgradePathLocation,
UpgradeNode: upgradeNode,
Outdir: outdir,
Upgrade: upgrade,
UpgradePathLocation: upgradePathLocation,
UpgradeNode: upgradeNode,
DistroPatchesLocation: distroPatchesLocation,
ClusterSkipsCmdFlags: skips,
}, nil
}

Expand Down Expand Up @@ -438,7 +460,14 @@ func setupCreateClusterCmdFlags(cmd *cobra.Command) {
"Location where to download schemas, defaults and the distribution manifests from. "+
"It can either be a local path (eg: /path/to/fury/distribution) or "+
"a remote URL (eg: git::[email protected]:sighupio/fury-distribution?depth=1&ref=BRANCH_NAME). "+
"Any format supported by hashicorp/go-getter can be used.",
cmdutil.AnyGoGetterFormatStr,
)

cmd.Flags().String(
"distro-patches",
"",
"Location where to download distribution's user-made patches from. "+
cmdutil.AnyGoGetterFormatStr,
)

cmd.Flags().StringP(
Expand Down
16 changes: 14 additions & 2 deletions cmd/create/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ func NewConfigCommand(tracker *analytics.Tracker) *cobra.Command {
return fmt.Errorf("%w: %w", ErrParsingFlag, err)
}

distroPatchesLocation, err := cmdutil.StringFlag(cmd, "distro-patches", tracker, cmdEvent)
if err != nil {
return fmt.Errorf("%w: %s", ErrParsingFlag, "distro-patches")
}

minimalConf := distroconf.Furyctl{
APIVersion: apiVersion,
Kind: kind,
Expand Down Expand Up @@ -130,9 +135,9 @@ func NewConfigCommand(tracker *analytics.Tracker) *cobra.Command {
depsvl := dependencies.NewValidator(executor, "", "", false)

if distroLocation == "" {
distrodl = distribution.NewCachingDownloader(client, outDir, typedGitProtocol)
distrodl = distribution.NewCachingDownloader(client, outDir, typedGitProtocol, distroPatchesLocation)
} else {
distrodl = distribution.NewDownloader(client, typedGitProtocol)
distrodl = distribution.NewDownloader(client, typedGitProtocol, distroPatchesLocation)
}

// Init packages.
Expand Down Expand Up @@ -217,6 +222,13 @@ func NewConfigCommand(tracker *analytics.Tracker) *cobra.Command {
"Any format supported by hashicorp/go-getter can be used.",
)

cmd.Flags().String(
"distro-patches",
"",
"Location where to download distribution's user-made patches from. "+
cmdutil.AnyGoGetterFormatStr,
)

cmd.Flags().StringP(
"version",
"v",
Expand Down
74 changes: 44 additions & 30 deletions cmd/delete/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,21 @@ var (
)

type ClusterCmdFlags struct {
Debug bool
FuryctlPath string
DistroLocation string
Phase string
BinPath string
Force bool
SkipVpn bool
VpnAutoConnect bool
DryRun bool
NoTTY bool
GitProtocol git.Protocol
Outdir string
SkipDepsDownload bool
SkipDepsValidation bool
Debug bool
FuryctlPath string
DistroLocation string
Phase string
BinPath string
Force bool
SkipVpn bool
VpnAutoConnect bool
DryRun bool
NoTTY bool
GitProtocol git.Protocol
Outdir string
SkipDepsDownload bool
SkipDepsValidation bool
DistroPatchesLocation string
}

func NewClusterCmd(tracker *analytics.Tracker) *cobra.Command {
Expand Down Expand Up @@ -101,9 +102,9 @@ func NewClusterCmd(tracker *analytics.Tracker) *cobra.Command {
depsvl := dependencies.NewValidator(executor, flags.BinPath, flags.FuryctlPath, flags.VpnAutoConnect)

if flags.DistroLocation == "" {
distrodl = distribution.NewCachingDownloader(client, outDir, flags.GitProtocol)
distrodl = distribution.NewCachingDownloader(client, outDir, flags.GitProtocol, flags.DistroPatchesLocation)
} else {
distrodl = distribution.NewDownloader(client, flags.GitProtocol)
distrodl = distribution.NewDownloader(client, flags.GitProtocol, flags.DistroPatchesLocation)
}

execx.NoTTY = flags.NoTTY
Expand Down Expand Up @@ -267,6 +268,13 @@ func NewClusterCmd(tracker *analytics.Tracker) *cobra.Command {
"Any format supported by hashicorp/go-getter can be used.",
)

cmd.Flags().String(
"distro-patches",
"",
"Location where to download distribution's user-made patches from. "+
cmdutil.AnyGoGetterFormatStr,
)

cmd.Flags().StringP(
"bin-path",
"b",
Expand Down Expand Up @@ -407,20 +415,26 @@ func getDeleteClusterCmdFlags(cmd *cobra.Command, tracker *analytics.Tracker, cm
return ClusterCmdFlags{}, fmt.Errorf(WrappedErrMessage, ErrParsingFlag, "skip-deps-validation")
}

distroPatchesLocation, err := cmdutil.StringFlag(cmd, "distro-patches", tracker, cmdEvent)
if err != nil {
return ClusterCmdFlags{}, fmt.Errorf("%w: %s", ErrParsingFlag, "distro-patches")
}

return ClusterCmdFlags{
Debug: debug,
FuryctlPath: furyctlPath,
DistroLocation: distroLocation,
Phase: phase,
BinPath: binPath,
SkipVpn: skipVpn,
VpnAutoConnect: vpnAutoConnect,
DryRun: dryRun,
Force: force,
NoTTY: noTTY,
GitProtocol: typedGitProtocol,
Outdir: outdir,
SkipDepsDownload: skipDepsDownload,
SkipDepsValidation: skipDepsValidation,
Debug: debug,
FuryctlPath: furyctlPath,
DistroLocation: distroLocation,
Phase: phase,
BinPath: binPath,
SkipVpn: skipVpn,
VpnAutoConnect: vpnAutoConnect,
DryRun: dryRun,
Force: force,
NoTTY: noTTY,
GitProtocol: typedGitProtocol,
Outdir: outdir,
SkipDepsDownload: skipDepsDownload,
SkipDepsValidation: skipDepsValidation,
DistroPatchesLocation: distroPatchesLocation,
}, nil
}
Loading

0 comments on commit 017cfdc

Please sign in to comment.