Skip to content

Commit

Permalink
Add new api publicAPIServerURL
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielXLee committed Jul 11, 2021
1 parent 6976986 commit fbaa6c5
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 7 deletions.
46 changes: 41 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
- [Example](#example)
- [Prerequisites](#prerequisites)
- [Quickstart](#quickstart)
- [Verify](#verify)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

Expand Down Expand Up @@ -83,9 +84,11 @@ The setup can be done by using `kustomize`.
```

- Deploy broker on `cluster-a`


Add `publicAPIServerURL` in `./config/samples/deploy_broker.yaml`, find the public apiserver URL with command: `kubectl config view | grep server | cut -f 2- -d ":" | tr -d " "`

```shell
kubect -n knitnet-operator-system apply -f .config/samples/deploy_broker.yaml
kubectl -n knitnet-operator-system apply -f ./config/samples/deploy_broker.yaml
```

- Export `submariner-broker-info` configmap to a yaml file
Expand All @@ -94,7 +97,7 @@ The setup can be done by using `kustomize`.
kubectl -n submariner-k8s-broker get cm submariner-broker-info -oyaml > submariner-k8s-broker.yaml
```

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

- Install knitnet operator

Expand All @@ -106,11 +109,44 @@ The setup can be done by using `kustomize`.
- Create `submariner-broker-info` configmap

```shell
kubectl create ns submariner-k8s-broker
kubectl apply -f submariner-k8s-broker.yaml
```

- Join `cluster-a` to `cluster-b`
- Join `cluster-b` to `cluster-a`

```shell
kubectl -n knitnet-operator-system apply -f .config/samples/join_broker.yaml
kubectl -n knitnet-operator-system apply -f ./config/samples/join_broker.yaml
```

### Verify

1. Deploy ClusterIP service on `cluster-b`

```shell
kubectl config use-context cluster-b
kubectl -n default create deployment nginx --image=nginx
kubectl -n default expose deployment nginx --port=8080
```

1. Export service

Create following resource on `cluster-b`:

```shell
kubectl apply -f - <<EOF
apiVersion: multicluster.x-k8s.io/v1alpha1
kind: ServiceExport
metadata:
name: nginx
namespace: default
EOF
```
1. Run `nettest` from `cluster-a` to access the nginx service:
```shell
kubectl config use-context cluster-a
kubectl -n default run --generator=run-pod/v1 tmp-shell --rm -i --tty --image quay.io/submariner/nettest -- /bin/bash
curl nginx.default.svc.clusterset.local:8080
```
3 changes: 3 additions & 0 deletions api/v1alpha1/knitnet_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ const (
type Phase string

type BrokerConfig struct {
// PublicAPIServerURL represents public access kubernetes API server address.
// +optional
PublicAPIServerURL string `json:"publicAPIServerURL,omitempty"`
// ConnectivityEnabled represents enable/disable multi-cluster pod connectivity.
// +optional
// +kubebuilder:default=true
Expand Down
4 changes: 4 additions & 0 deletions config/crd/bases/operator.tkestack.io_knitnets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ spec:
description: GlobalnetEnable represents enable/disable overlapping
CIDRs in connecting clusters (default disabled).
type: boolean
publicAPIServerURL:
description: PublicAPIServerURL represents public access kubernetes
API server address.
type: string
serviceDiscoveryEnabled:
default: false
description: ServiceDiscoveryEnabled represents enable/disable
Expand Down
2 changes: 2 additions & 0 deletions config/samples/deploy_broker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ metadata:
name: deploy-broker-sample
spec:
brokerConfig:
publicAPIServerURL: https://xxx.myqcloud.com
# defaultGlobalnetClusterSize: 65336
globalnetCIDRRange: 242.0.0.0/16
serviceDiscoveryEnabled: true
6 changes: 5 additions & 1 deletion controllers/ensures/broker/brokerinfo_cm.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ func NewFromCluster(c client.Client, restConfig *rest.Config) (*BrokerInfo, erro
if err != nil {
return nil, err
}
brokerInfo.BrokerURL = restConfig.Host + restConfig.APIPath
return brokerInfo, err
}

Expand All @@ -150,6 +149,11 @@ func CreateBrokerInfoConfigMap(c client.Client, restConfig *rest.Config, instanc
return err
}
brokerConfig := instance.Spec.BrokerConfig
if brokerConfig.PublicAPIServerURL != "" {
brokerInfo.BrokerURL = brokerConfig.PublicAPIServerURL
} else {
brokerInfo.BrokerURL = restConfig.Host + restConfig.APIPath
}
brokerInfo.GlobalnetCIDRRange = brokerConfig.GlobalnetCIDRRange
brokerInfo.DefaultGlobalnetClusterSize = brokerConfig.DefaultGlobalnetClusterSize
componentSet := stringset.New()
Expand Down
3 changes: 2 additions & 1 deletion controllers/join_broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ func (r *KnitnetReconciler) JoinSubmarinerCluster(instance *operatorv1alpha1.Kni
return err
}
klog.Info("Submariner is up and running")
} else if brokerInfo.IsServiceDiscoveryEnabled() {
}
if brokerInfo.IsServiceDiscoveryEnabled() {
klog.Info("Deploying service discovery only")
serviceDiscoverySpec, err := populateServiceDiscoverySpec(instance, brokerInfo)
if err != nil {
Expand Down

0 comments on commit fbaa6c5

Please sign in to comment.