Skip to content

Commit

Permalink
Fix globalnet issue
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielXLee committed Jul 13, 2021
1 parent dae7b01 commit 8c57384
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 19 deletions.
46 changes: 33 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ The configuration of Knitnet setup should be described in Knitnet CRD. You will

### Prerequisites

Knitnet operator requires a Kubernetes cluster of version `>=1.5.0`. If you have just started with Operators, its highly recommended to use latest version of Kubernetes. And the prepare 2 cluster, example `cluster-a` and `cluster-b`
Knitnet operator requires a Kubernetes cluster of version `>=1.15.0`. If you have just started with Operators, its highly recommended to use latest version of Kubernetes. And the prepare 2 cluster, example `cluster-a` and `cluster-b`

### Quickstart

Expand All @@ -77,11 +77,17 @@ The setup can be done by using `kustomize`.

- Install knitnet operator

```shell
kubectl config use-context cluster-a
cd knitnet-operator
make deploy
```
Switch to `cluster-a`

```shell
kubectl config use-context cluster-b
```

Deploy operator

```shell
make deploy
```

- Deploy broker on `cluster-a`

Expand All @@ -94,22 +100,29 @@ The setup can be done by using `kustomize`.
- Export `submariner-broker-info` configmap to a yaml file

```shell
kubectl -n knitnet-operator-system get cm submariner-broker-info -oyaml > submariner-k8s-broker.yaml
kubectl -n knitnet-operator-system get cm submariner-broker-info -oyaml > submariner-broker-info.yaml
```

1. Join cluster to broker
2. Join cluster to broker

- Install knitnet operator

```shell
kubectl config use-context cluster-b
make deploy
```
Switch to `cluster-b`

```shell
kubectl config use-context cluster-b
```

Deploy operator

```shell
make deploy
```

- Create `submariner-broker-info` configmap

```shell
kubectl apply -f submariner-k8s-broker.yaml
kubectl apply -f submariner-broker-info.yaml
```

- Join `cluster-b` to `cluster-a`
Expand All @@ -122,8 +135,15 @@ The setup can be done by using `kustomize`.

1. Deploy ClusterIP service on `cluster-b`

Switch to `cluster-b`

```shell
kubectl config use-context cluster-b
```

Deploy `nginx` service

```shell
kubectl -n default create deployment nginx --image=nginx
kubectl -n default expose deployment nginx --port=80
```
Expand Down
1 change: 0 additions & 1 deletion config/samples/deploy_broker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ spec:
brokerConfig:
publicAPIServerURL: https://xxx.myqcloud.com
# defaultGlobalnetClusterSize: 65336
globalnetCIDRRange: 242.0.0.0/16
serviceDiscoveryEnabled: true
12 changes: 12 additions & 0 deletions controllers/deploy_broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
submarinerv1a1 "github.com/submariner-io/submariner-operator/apis/submariner/v1alpha1"
"k8s.io/klog/v2"

"github.com/tkestack/knitnet-operator/controllers/components"
consts "github.com/tkestack/knitnet-operator/controllers/ensures"

"github.com/tkestack/knitnet-operator/controllers/discovery/globalnet"
Expand Down Expand Up @@ -115,10 +116,21 @@ func isValidGlobalnetConfig(instance *operatorv1alpha1.Knitnet) (bool, error) {

func populateBrokerSpec(instance *operatorv1alpha1.Knitnet) submarinerv1a1.BrokerSpec {
brokerConfig := instance.Spec.BrokerConfig
enabledComponents := []string{}
if brokerConfig.ConnectivityEnabled {
enabledComponents = append(enabledComponents, components.Connectivity)
}
if brokerConfig.GlobalnetEnable {
enabledComponents = append(enabledComponents, components.Globalnet)
}
if brokerConfig.ServiceDiscoveryEnabled {
enabledComponents = append(enabledComponents, components.ServiceDiscovery)
}
brokerSpec := submarinerv1a1.BrokerSpec{
GlobalnetEnabled: brokerConfig.GlobalnetEnable,
GlobalnetCIDRRange: brokerConfig.GlobalnetCIDRRange,
DefaultGlobalnetClusterSize: brokerConfig.DefaultGlobalnetClusterSize,
Components: enabledComponents,
DefaultCustomDomains: brokerConfig.DefaultCustomDomains,
}
return brokerSpec
Expand Down
1 change: 1 addition & 0 deletions controllers/ensures/broker/brokerinfo_cm.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ func NewFromConfigMap(c client.Client) (*BrokerInfo, error) {
cm := &v1.ConfigMap{}
cmKey := types.NamespacedName{Name: consts.SubmarinerBrokerInfo, Namespace: consts.KnitnetOperatorNamespace}
if err := c.Get(context.TODO(), cmKey, cm); err != nil {
klog.Errorf("Get submariner-broker-info configmap failed: %v", err)
return nil, err
}
return NewFromString(cm.Data["brokerInfo"])
Expand Down
8 changes: 3 additions & 5 deletions controllers/join_broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ func (r *KnitnetReconciler) JoinSubmarinerCluster(instance *operatorv1alpha1.Kni
ServiceCIDRAutoDetected: serviceCIDRautoDetected,
ClusterCIDR: clusterCIDR,
ClusterCIDRAutoDetected: clusterCIDRautoDetected,
GlobalnetCIDR: brokerInfo.GlobalnetCIDRRange,
GlobalnetClusterSize: brokerInfo.DefaultGlobalnetClusterSize,
GlobalnetCIDR: joinConfig.GlobalnetCIDR,
GlobalnetClusterSize: joinConfig.GlobalnetClusterSize,
}
if brokerInfo.IsGlobalnetEnabled() {
if err = r.AllocateAndUpdateGlobalCIDRConfigMap(brokerCluster.GetClient(), brokerCluster.GetAPIReader(), instance, brokerNamespace, &netconfig); err != nil {
Expand Down Expand Up @@ -167,8 +167,7 @@ func (r *KnitnetReconciler) JoinSubmarinerCluster(instance *operatorv1alpha1.Kni
return err
}
klog.Info("Submariner is up and running")
}
if brokerInfo.IsServiceDiscoveryEnabled() {
} else if brokerInfo.IsServiceDiscoveryEnabled() {
klog.Info("Deploying service discovery only")
serviceDiscoverySpec, err := populateServiceDiscoverySpec(instance, brokerInfo)
if err != nil {
Expand Down Expand Up @@ -322,7 +321,6 @@ func populateSubmarinerSpec(instance *operatorv1alpha1.Knitnet, brokerInfo *brok
CableDriver: joinConfig.CableDriver,
ServiceDiscoveryEnabled: brokerInfo.IsServiceDiscoveryEnabled(),
ImageOverrides: imageOverrides,
GlobalCIDR: brokerInfo.GlobalnetCIDRRange,
}
if netconfig.GlobalnetCIDR != "" {
submarinerSpec.GlobalCIDR = netconfig.GlobalnetCIDR
Expand Down

0 comments on commit 8c57384

Please sign in to comment.