Skip to content

Commit

Permalink
Add new api arg to select deploy broker or join broker
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielXLee committed Jul 9, 2021
1 parent 61f2658 commit 7ec0dfb
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 19 deletions.
5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,7 @@ build: generate generate-embeddedyamls fmt vet ## Build manager binary.
go build -o bin/manager main.go

run: manifests generate fmt vet ## Run a controller for deploy broker.
go run ./main.go --deploy-broker=true

run-join: manifests generate fmt vet ## Run a controller for join broker.
go run ./main.go --join-broker=true
go run ./main.go

docker-build: test ## Build docker image with the manager.
docker build -t ${IMG} .
Expand Down
6 changes: 6 additions & 0 deletions api/v1alpha1/fabric_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ type FabricSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

// Action represents deploy broker or join cluster to broker
// +optional
// +kubebuilder:default=broker
// +kubebuilder:validation:Enum=broker;join;all
Action string `json:"action,omitempty"`

// BrokerConfig represents the broker cluster configuration of the Submariner.
// +optional
BrokerConfig `json:"brokerConfig,omitempty"`
Expand Down
8 changes: 8 additions & 0 deletions config/crd/bases/operator.tkestack.io_fabrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ spec:
spec:
description: FabricSpec defines the desired state of Fabric
properties:
action:
default: broker
description: Action represents deploy broker or join cluster to broker
enum:
- broker
- join
- all
type: string
brokerConfig:
description: BrokerConfig represents the broker cluster configuration
of the Submariner.
Expand Down
14 changes: 9 additions & 5 deletions controllers/fabric_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,15 @@ type FabricReconciler struct {
client.Client
client.Reader
*rest.Config
Scheme *runtime.Scheme
DeployBroker bool
JoinBroker bool
Scheme *runtime.Scheme
}

const (
BrokerAction = "broker"
JoinAction = "join"
AllAction = "all"
)

//+kubebuilder:rbac:groups=operator.tkestack.io,resources=fabrics,verbs=get;list;watch;create;update;patch;delete
//+kubebuilder:rbac:groups=operator.tkestack.io,resources=fabrics/status,verbs=get;update;patch
//+kubebuilder:rbac:groups=operator.tkestack.io,resources=fabrics/finalizers,verbs=update
Expand Down Expand Up @@ -91,15 +95,15 @@ func (r *FabricReconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ c
}()

// Deploy submeriner broker
if r.DeployBroker {
if instance.Spec.Action == BrokerAction || instance.Spec.Action == AllAction {
klog.Info("Deploy submeriner broker")
if err := r.DeploySubmerinerBroker(instance); err != nil {
return ctrl.Result{}, err
}
}

// Join managed cluster to submeriner borker
if r.JoinBroker {
if instance.Spec.Action == JoinAction || instance.Spec.Action == AllAction {
klog.Info("Join managed cluster to submeriner broker")
brokerInfo, err := broker.NewFromConfigMap(r.Client)
if err != nil {
Expand Down
14 changes: 4 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,12 @@ func main() {
var metricsAddr string
var enableLeaderElection bool
var probeAddr string
var deployBroker bool
var joinBroker bool

flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
flag.BoolVar(&deployBroker, "deploy-broker", false, "Enable deploy broker for controller manager. ")
flag.BoolVar(&joinBroker, "join-broker", false, "Enable join managed to broker for controller manager. ")

klog.InitFlags(nil)
defer klog.Flush()
Expand All @@ -83,12 +79,10 @@ func main() {
}

if err = (&controllers.FabricReconciler{
Client: mgr.GetClient(),
Reader: mgr.GetAPIReader(),
Config: mgr.GetConfig(),
Scheme: mgr.GetScheme(),
DeployBroker: deployBroker,
JoinBroker: joinBroker,
Client: mgr.GetClient(),
Reader: mgr.GetAPIReader(),
Config: mgr.GetConfig(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
klog.Errorf("unable to create controller Fabric: %v", err)
os.Exit(1)
Expand Down

0 comments on commit 7ec0dfb

Please sign in to comment.