Skip to content

Commit

Permalink
Deprecates some IPFS flags (#3778)
Browse files Browse the repository at this point in the history
In order to smooth the migration from an embedded IPFS node to a
self-hosted IPFS node, we will deprecate the flags used for the internal
node, rather than removing the functionality in one release.

This will allow for the functionality to be removed over two or more
minor version releases.

The Definition type has two new fields, a boolean Deprecated field and a
string DeprecatedMessage field. if the former is set then we mark the
flag as deprecated and show the second field.
  • Loading branch information
rossjones authored Apr 11, 2024
1 parent 67eaa11 commit cae6305
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 17 deletions.
49 changes: 33 additions & 16 deletions cmd/util/flags/configflags/ipfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ package configflags

import "github.com/bacalhau-project/bacalhau/pkg/config/types"

const ipfsEmbeddedDeprecationMessage = "The embedded IPFS node will be removed in a future version" +
"in favour of using --ipfs-connect and a self-hosted IPFS node"

var IPFSFlags = []Definition{
{
FlagName: "ipfs-swarm-addrs",
ConfigPath: types.NodeIPFSSwarmAddresses,
DefaultValue: Default.Node.IPFS.SwarmAddresses,
Description: "IPFS multiaddress to connect the in-process IPFS node to - cannot be used with --ipfs-connect.",
EnvironmentVariables: []string{"BACALHAU_IPFS_SWARM_ADDRESSES"},
Deprecated: true,
DeprecatedMessage: ipfsEmbeddedDeprecationMessage,
},
{
FlagName: "ipfs-swarm-key",
Expand All @@ -31,36 +36,48 @@ var IPFSFlags = []Definition{
"cannot be used with --ipfs-connect. " +
"Use \"--private-internal-ipfs=false\" to disable. " +
"To persist a local Ipfs node, set BACALHAU_SERVE_IPFS_PATH to a valid path.",
Deprecated: true,
DeprecatedMessage: ipfsEmbeddedDeprecationMessage,
},
{
FlagName: "ipfs-serve-path",
ConfigPath: types.NodeIPFSServePath,
DefaultValue: Default.Node.IPFS.ServePath,
Description: "path local Ipfs node will persist data to",
EnvironmentVariables: []string{"BACALHAU_SERVE_IPFS_PATH"},
Deprecated: true,
DeprecatedMessage: ipfsEmbeddedDeprecationMessage,
},
{
FlagName: "ipfs-profile",
ConfigPath: types.NodeIPFSProfile,
DefaultValue: Default.Node.IPFS.Profile,
Description: "profile for internal IPFS node",
FlagName: "ipfs-profile",
ConfigPath: types.NodeIPFSProfile,
DefaultValue: Default.Node.IPFS.Profile,
Description: "profile for internal IPFS node",
Deprecated: true,
DeprecatedMessage: ipfsEmbeddedDeprecationMessage,
},
{
FlagName: "ipfs-swarm-listen-addresses",
ConfigPath: types.NodeIPFSSwarmListenAddresses,
DefaultValue: Default.Node.IPFS.SwarmListenAddresses,
Description: "addresses the internal IPFS node will listen on for swarm connections",
FlagName: "ipfs-swarm-listen-addresses",
ConfigPath: types.NodeIPFSSwarmListenAddresses,
DefaultValue: Default.Node.IPFS.SwarmListenAddresses,
Description: "addresses the internal IPFS node will listen on for swarm connections",
Deprecated: true,
DeprecatedMessage: ipfsEmbeddedDeprecationMessage,
},
{
FlagName: "ipfs-gateway-listen-addresses",
ConfigPath: types.NodeIPFSGatewayListenAddresses,
DefaultValue: Default.Node.IPFS.GatewayListenAddresses,
Description: "addresses the internal IPFS node will listen on for gateway connections",
FlagName: "ipfs-gateway-listen-addresses",
ConfigPath: types.NodeIPFSGatewayListenAddresses,
DefaultValue: Default.Node.IPFS.GatewayListenAddresses,
Description: "addresses the internal IPFS node will listen on for gateway connections",
Deprecated: true,
DeprecatedMessage: ipfsEmbeddedDeprecationMessage,
},
{
FlagName: "ipfs-api-listen-addresses",
ConfigPath: types.NodeIPFSAPIListenAddresses,
DefaultValue: Default.Node.IPFS.APIListenAddresses,
Description: "addresses the internal IPFS node will listen on for API connections",
FlagName: "ipfs-api-listen-addresses",
ConfigPath: types.NodeIPFSAPIListenAddresses,
DefaultValue: Default.Node.IPFS.APIListenAddresses,
Description: "addresses the internal IPFS node will listen on for API connections",
Deprecated: true,
DeprecatedMessage: ipfsEmbeddedDeprecationMessage,
},
}
9 changes: 8 additions & 1 deletion cmd/util/flags/configflags/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ type Definition struct {
DefaultValue interface{}
Description string
EnvironmentVariables []string
Deprecated bool
DeprecatedMessage string
}

// BindFlags binds flags from a command to Viper using the provided definitions.
Expand All @@ -47,7 +49,7 @@ func BindFlags(cmd *cobra.Command, register map[string][]Definition) error {
// set the default value
viper.SetDefault(def.ConfigPath, def.DefaultValue)

// bind the flag to viper
// Bind the flag to viper
if err := viper.BindPFlag(def.ConfigPath, cmd.Flags().Lookup(def.FlagName)); err != nil {
return err
}
Expand Down Expand Up @@ -107,6 +109,11 @@ func RegisterFlags(cmd *cobra.Command, register map[string][]Definition) error {
default:
return fmt.Errorf("unhandled type: %T for flag %s", v, def.FlagName)
}

if def.Deprecated {
flag := fset.Lookup(def.FlagName)
flag.Deprecated = def.DeprecatedMessage
}
}
cmd.PersistentFlags().AddFlagSet(fset)
}
Expand Down

0 comments on commit cae6305

Please sign in to comment.