Skip to content

Commit

Permalink
Allow overriding the broker API endpoint URL
Browse files Browse the repository at this point in the history
In some setups, the broker URL determined from the kubeconfig context
isn't usable from the clusters which will be joined. For these setups,
the broker URL needs to be overridden, and this implements that by
adding a --broker-url option to the following subctl sub-commands:

* deploy-broker, to override the URL stored in the generated
  broker-info.subm file
* recover-broker-info, for the same reason
* join, to override the URL retrieved from the broker-info.subm file

Thus when the user knows ahead of time that the broker URL needs to be
manually specified, they can provide the correct setting to
deploy-broker, and join works as before. If they didn't know when
deploy-broker was run, they can specify the correct URL when joining
clusters. This also handles setups where each joining cluster might
need a different URL to reach the broker.

Signed-off-by: Stephen Kitt <[email protected]>
  • Loading branch information
skitt committed Nov 30, 2023
1 parent 2549dd7 commit 43974a5
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 5 deletions.
5 changes: 4 additions & 1 deletion cmd/subctl/deploybroker.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ func addDeployBrokerFlags(flags *pflag.FlagSet) {
flags.StringVar(&deployflags.ImageVersion, "version", "", "image version")

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 @@ -114,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
5 changes: 4 additions & 1 deletion cmd/subctl/recover_broker_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
)

var recoverRestConfigProducer = restconfig.NewProducer()
var recoverBrokerURL string

// recoverBrokerInfo represents the reconstruct command.
var recoverBrokerInfo = &cobra.Command{
Expand All @@ -48,6 +49,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 +87,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
}

0 comments on commit 43974a5

Please sign in to comment.