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

Allow overriding the broker API endpoint URL #1017

Merged
merged 3 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
28 changes: 16 additions & 12 deletions cmd/subctl/deploybroker.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/submariner-io/admiral/pkg/reporter"
"github.com/submariner-io/subctl/internal/cli"
"github.com/submariner-io/subctl/internal/component"
Expand Down Expand Up @@ -58,32 +59,35 @@ var deployBroker = &cobra.Command{
}

func init() {
addDeployBrokerFlags()
addDeployBrokerFlags(deployBroker.Flags())
deployRestConfigProducer.SetupFlags(deployBroker.Flags())
rootCmd.AddCommand(deployBroker)
}

func addDeployBrokerFlags() {
deployBroker.PersistentFlags().BoolVar(&deployflags.BrokerSpec.GlobalnetEnabled, "globalnet", false,
func addDeployBrokerFlags(flags *pflag.FlagSet) {
flags.BoolVar(&deployflags.BrokerSpec.GlobalnetEnabled, "globalnet", false,
"enable support for Overlapping CIDRs in connecting clusters (default disabled)")
deployBroker.PersistentFlags().StringVar(&deployflags.BrokerSpec.GlobalnetCIDRRange, "globalnet-cidr-range",
flags.StringVar(&deployflags.BrokerSpec.GlobalnetCIDRRange, "globalnet-cidr-range",
globalnet.DefaultGlobalnetCIDR, "GlobalCIDR supernet range for allocating GlobalCIDRs to each cluster")
deployBroker.PersistentFlags().UintVar(&deployflags.BrokerSpec.DefaultGlobalnetClusterSize, "globalnet-cluster-size",
flags.UintVar(&deployflags.BrokerSpec.DefaultGlobalnetClusterSize, "globalnet-cluster-size",
globalnet.DefaultGlobalnetClusterSize, "default cluster size for GlobalCIDR allocated to each cluster (amount of global IPs)")

deployBroker.PersistentFlags().StringVar(&ipsecSubmFile, "ipsec-psk-from", "",
flags.StringVar(&ipsecSubmFile, "ipsec-psk-from", "",
"import IPsec PSK from existing submariner broker file, like broker-info.subm")

deployBroker.PersistentFlags().StringSliceVar(&deployflags.BrokerSpec.DefaultCustomDomains, "custom-domains", nil,
flags.StringSliceVar(&deployflags.BrokerSpec.DefaultCustomDomains, "custom-domains", nil,
"list of domains to use for multicluster service discovery")

deployBroker.PersistentFlags().StringSliceVar(&deployflags.BrokerSpec.Components, "components", defaultComponents,
flags.StringSliceVar(&deployflags.BrokerSpec.Components, "components", defaultComponents,
fmt.Sprintf("The components to be installed - any of %s", strings.Join(deploy.ValidComponents, ",")))

deployBroker.PersistentFlags().StringVar(&deployflags.Repository, "repository", "", "image repository")
deployBroker.PersistentFlags().StringVar(&deployflags.ImageVersion, "version", "", "image version")
flags.StringVar(&deployflags.Repository, "repository", "", "image repository")
flags.StringVar(&deployflags.ImageVersion, "version", "", "image version")

deployBroker.PersistentFlags().BoolVar(&deployflags.OperatorDebug, "operator-debug", false, "enable operator debugging (verbose logging)")
flags.BoolVar(&deployflags.OperatorDebug, "operator-debug", false, "enable operator debugging (verbose logging)")

flags.StringVar(&deployflags.BrokerURL, "broker-url", "",
"broker API endpoint URL (stored in the broker information file, defaults to the context URL)")
}

func deployBrokerInContext(clusterInfo *cluster.Info, namespace string, status reporter.Interface) error {
Expand Down Expand Up @@ -113,6 +117,6 @@ func deployBrokerInContext(clusterInfo *cluster.Info, namespace string, status r
}

return broker.WriteInfoToFile( //nolint:wrapcheck // No need to wrap errors here.
clusterInfo.RestConfig, namespace, ipsecPSK,
clusterInfo.RestConfig, namespace, deployflags.BrokerURL, ipsecPSK,
set.New(deployflags.BrokerSpec.Components...), deployflags.BrokerSpec.DefaultCustomDomains, status)
}
7 changes: 7 additions & 0 deletions cmd/subctl/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ var joinCmd = &cobra.Command{
exit.OnError(status.Error(err, "Error loading the broker information from the given file"))
status.Success("%s indicates broker is at %s", args[0], brokerInfo.BrokerURL)

if joinFlags.BrokerURL != "" {
status.Success("Overriding broker URL using %s", joinFlags.BrokerURL)
brokerInfo.BrokerURL = joinFlags.BrokerURL
}

exit.OnError(joinRestConfigProducer.RunOnSelectedContext(
func(clusterInfo *cluster.Info, namespace string, status reporter.Interface) error {
return joinInContext(brokerInfo, clusterInfo, status)
Expand Down Expand Up @@ -127,6 +132,8 @@ func addJoinFlags(cmd *cobra.Command) {

cmd.Flags().BoolVar(&joinFlags.BrokerK8sSecure, "check-broker-certificate", true,
"check the broker certificate (disable this to allow \"insecure\" connections)")
cmd.Flags().StringVar(&joinFlags.BrokerURL, "broker-url", "",
"URL of the broker API endpoint (overrides the URL stored in the broker information file)")
}

func joinInContext(brokerInfo *broker.Info, clusterInfo *cluster.Info, status reporter.Interface) error {
Expand Down
9 changes: 7 additions & 2 deletions cmd/subctl/recover_broker_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ import (
"github.com/submariner-io/subctl/pkg/cluster"
)

var recoverRestConfigProducer = restconfig.NewProducer()
var (
recoverRestConfigProducer = restconfig.NewProducer()
recoverBrokerURL string
)

// recoverBrokerInfo represents the reconstruct command.
var recoverBrokerInfo = &cobra.Command{
Expand All @@ -48,6 +51,8 @@ var recoverBrokerInfo = &cobra.Command{

func init() {
recoverRestConfigProducer.SetupFlags(recoverBrokerInfo.Flags())
recoverBrokerInfo.Flags().StringVar(&recoverBrokerURL, "broker-url", "",
"broker API endpoint URL (stored in the broker information file, defaults to the context URL)")
rootCmd.AddCommand(recoverBrokerInfo)
}

Expand Down Expand Up @@ -84,5 +89,5 @@ func recoverBrokerInfoFromSubm(submCluster *cluster.Info, _ string, status repor
}

//nolint:wrapcheck // No need to wrap errors here.
return broker.RecoverData(submCluster, brokerObj, brokerNamespace, brokerRestConfig, status)
return broker.RecoverData(submCluster, brokerObj, brokerNamespace, recoverBrokerURL, brokerRestConfig, status)
}
6 changes: 5 additions & 1 deletion pkg/broker/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import (

const InfoFileName = "broker-info.subm"

func WriteInfoToFile(restConfig *rest.Config, brokerNamespace string, ipsecPSK []byte, components set.Set[string],
func WriteInfoToFile(restConfig *rest.Config, brokerNamespace, brokerURL string, ipsecPSK []byte, components set.Set[string],
customDomains []string, status reporter.Interface,
) error {
status.Start("Saving broker info to file %q", InfoFileName)
Expand Down Expand Up @@ -70,6 +70,10 @@ func WriteInfoToFile(restConfig *rest.Config, brokerNamespace string, ipsecPSK [

data.BrokerURL = restConfig.Host + restConfig.APIPath

if brokerURL != "" {
data.BrokerURL = brokerURL
}

data.ServiceDiscovery = components.Has(component.ServiceDiscovery)
data.Components = components.UnsortedList()
sort.Strings(data.Components)
Expand Down
4 changes: 2 additions & 2 deletions pkg/broker/recover_broker_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"k8s.io/utils/set"
)

func RecoverData(submCluster *cluster.Info, broker *v1alpha1.Broker, brokerNamespace string,
func RecoverData(submCluster *cluster.Info, broker *v1alpha1.Broker, brokerNamespace, brokerURL string,
brokerRestConfig *rest.Config, status reporter.Interface,
) error {
status.Start("Retrieving data to reconstruct broker-info.subm")
Expand All @@ -43,7 +43,7 @@ func RecoverData(submCluster *cluster.Info, broker *v1alpha1.Broker, brokerNames

status.Success("Successfully retrieved the data. Writing it to broker-info.subm")

err = WriteInfoToFile(brokerRestConfig, brokerNamespace, decodedPSKSecret,
err = WriteInfoToFile(brokerRestConfig, brokerNamespace, brokerURL, decodedPSKSecret,
set.New(broker.Spec.Components...), broker.Spec.DefaultCustomDomains, status)

return status.Error(err, "error reconstructing broker-info.subm")
Expand Down
1 change: 1 addition & 0 deletions pkg/deploy/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type BrokerOptions struct {
Repository string
ImageVersion string
BrokerNamespace string
BrokerURL string
BrokerSpec operatorv1alpha1.BrokerSpec
}

Expand Down
1 change: 1 addition & 0 deletions pkg/join/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type Options struct {
ImageVersion string
CableDriver string
CoreDNSCustomConfigMap string
BrokerURL string
CustomDomains []string
ImageOverrideArr []string
}
Loading