Skip to content

Commit

Permalink
Support multi ces instances
Browse files Browse the repository at this point in the history
  • Loading branch information
myf5 committed Jan 4, 2022
2 parents e9be8f0 + 00ea2c3 commit 3152c72
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 57 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ GITHUBACTIONTRIGGERNUMBER = 4

REGISTRY = f5devcentral
NAME = ces-controller
RELEASE_TAG = 0.5.2
RELEASE_TAG = 0.5.3
COMMIT = git-$(shell git rev-parse --short HEAD)
DATE = $(shell date +"%Y-%m-%d_%H:%M:%S")
GOLDFLAGS = "-w -s -X github.com/kubeovn/$(NAME)/versions.COMMIT=$(COMMIT) -X github.com/kubeovn/$(NAME)/versions.VERSION=$(RELEASE_TAG) -X github.com/kubeovn/$(NAME)/versions.BUILDDATE=$(DATE)"
Expand Down
46 changes: 15 additions & 31 deletions cmd/ces/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ limitations under the License.
package main

import (
"context"
"flag"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strconv"
"time"

"github.com/kubeovn/ces-controller/pkg/as3"
Expand All @@ -31,7 +30,6 @@ import (
"github.com/kubeovn/ces-controller/pkg/signals"

"github.com/kubeovn/ces-controller/pkg/controller"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
kubeinformers "k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
Expand Down Expand Up @@ -98,39 +96,25 @@ func main() {
klog.Fatalf("Error building kubernetes clientset: %s", err.Error())
}

dm, err := kubeClient.AppsV1().Deployments("").List(context.Background(), metav1.ListOptions{
FieldSelector: fmt.Sprintf("metadata.name=%s", controller.ControllerAgentName),
})
if err != nil{
klog.Fatalf("failed to get deploy[%s]: %v", controller.ControllerAgentName, err)
}
if len(dm.Items) != 1{
klog.Fatalf("failed to get deploy[%s]", controller.ControllerAgentName)
}
ns := dm.Items[0].Namespace
cm, err := kubeClient.CoreV1().ConfigMaps(ns).Get(context.Background(), controller.ControllerConfigmap, metav1.GetOptions{})
if err != nil {
klog.Fatalf("failed to get configmap[%s]: %v", controller.ControllerConfigmap, err)
}

var initialized bool
if s := cm.Data["initialized"]; s != "" {
if initialized, err = strconv.ParseBool(s); err != nil {
klog.Fatalf("failed to parse bool value in configmap[%s]: %v", controller.ControllerConfigmap, err)
}
//dm, err := kubeClient.AppsV1().Deployments("").List(context.Background(), metav1.ListOptions{
// FieldSelector: fmt.Sprintf("metadata.name=%s", controller.ControllerAgentName),
//})
//if err != nil{
// klog.Fatalf("failed to get deploy[%s]: %v", controller.ControllerAgentName, err)
//}
//if len(dm.Items) != 1{
// klog.Fatalf("failed to get deploy[%s]", controller.ControllerAgentName)
//}
//ns := dm.Items[0].Namespace
controllerNamespace := os.Getenv("CES_NAMESPACE")
if controllerNamespace == "" {
klog.Fatal("env CES_NAMESPACE can't be empty ")
}
bigIpClient := as3.NewClient(bigipURL, bigipUsername, bigipPassword, bigipInsecure)
err = as3.InitAs3Tenant(bigIpClient, bigipConfDir, initialized, ns)
err = as3.InitAs3Tenant(bigIpClient, bigipConfDir, controllerNamespace)
if err != nil {
klog.Fatalf("failed to initialize AS3 declaration: %v", err)
}
if !initialized {
cm.Data["initialized"] = "true"
if _, err = kubeClient.CoreV1().ConfigMaps(ns).Update(context.Background(), cm, metav1.UpdateOptions{}); err != nil {
klog.Fatalf("failed to update configmap[%s]: %v", controller.ControllerConfigmap, err)
}
}

as3Client, err := clientset.NewForConfig(cfg)
if err != nil {
klog.Fatalf("Error building AS3 clientset: %s", err.Error())
Expand Down
29 changes: 14 additions & 15 deletions dist/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ BIGIP_USERNAME=${BIGIP_USERNAME:-} # BigIP username
BIGIP_PASSWORD=${BIGIP_PASSWORD:-} # BigIP password
BIGIP_INSECURE=${BIGIP_INSECURE:-true} # ignore Big-IP TLS error

K8S_NAMESPACE=${K8S_NAMESPACE:-kube-system} # namespace in which the controller will be deployed
CES_NAMESPACE=${CES_NAMESPACE:-kube-system} # namespace in which the controller will be deployed
CES_DEPLOMENT_NAME=${CES_DEPLOMENT_NAME:-ces-controller}

echo "[Step 1] Create Secret"
kubectl -n $K8S_NAMESPACE create secret generic --from-literal "username=$BIGIP_USERNAME" --from-literal "password=$BIGIP_PASSWORD" bigip-creds
kubectl -n $CES_NAMESPACE create secret generic --from-literal "username=$BIGIP_USERNAME" --from-literal "password=$BIGIP_PASSWORD" bigip-creds
echo "-------------------------------"
echo ""

Expand Down Expand Up @@ -246,7 +247,7 @@ apiVersion: v1
kind: ServiceAccount
metadata:
name: ces-controller
namespace: $K8S_NAMESPACE
namespace: $CES_NAMESPACE
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
Expand Down Expand Up @@ -315,7 +316,7 @@ metadata:
subjects:
- kind: ServiceAccount
name: ces-controller
namespace: $K8S_NAMESPACE
namespace: $CES_NAMESPACE
roleRef:
kind: ClusterRole
name: ces-controller
Expand All @@ -330,9 +331,8 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: ces-controller-configmap
namespace: $K8S_NAMESPACE
namespace: $CES_NAMESPACE
data:
initialized: "false"
ces-conf.yaml: |-
clusterName: k8s
isSupportRouteDomain: false
Expand Down Expand Up @@ -420,15 +420,11 @@ data:
- name: "Common"
namespaces: ""
virtualService:
template: ''
virtualAddress: "0.0.0.0"
icmpEcho: "disable"
arpEnabled: false
template: ''
virtualAddresses:
virtualAddress: "0.0.0.0"
icmpEcho: "disable"
arpEnabled: false
template: ''
gwPool:
serverAddresses:
- "10.5.0.254"
Expand All @@ -441,8 +437,8 @@ cat << EOF | kubectl apply -f -
apiVersion: apps/v1
kind: Deployment
metadata:
name: ces-controller
namespace: $K8S_NAMESPACE
name: $CES_DEPLOMENT_NAME
namespace: $CES_NAMESPACE
spec:
replicas: 1
selector:
Expand All @@ -456,7 +452,10 @@ spec:
serviceAccountName: ces-controller
containers:
- name: ces-controller
image: f5devcentral/ces-controller:0.5.2
image: f5devcentral/ces-controller:0.5.3
env:
- name: CES_NAMESPACE
value: $CES_NAMESPACE
imagePullPolicy: IfNotPresent
resources:
requests:
Expand Down Expand Up @@ -494,4 +493,4 @@ echo ""

echo "[Step 5] Wait CES Controller to Be Ready"
sleep 1s
kubectl -n $K8S_NAMESPACE wait pod --for=condition=Ready -l app=ces-controller
kubectl -n $CES_NAMESPACE wait pod --for=condition=Ready -l app=ces-controller
11 changes: 6 additions & 5 deletions dist/uninstall.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
#!/usr/bin/env bash
set -euo pipefail

K8S_NAMESPACE=${K8S_NAMESPACE:-kube-system} # namespace in which the controller will be deployed
CES_NAMESPACE=${CES_NAMESPACE:-kube-system} # namespace in which the controller will be deployed
CES_DEPLOMENT_NAME=${CES_DEPLOMENT_NAME:-ces-controller}

echo "[Step 1] Delete CES Controller"
kubectl -n $K8S_NAMESPACE delete --ignore-not-found deployment ces-controller
kubectl -n $CES_NAMESPACE delete --ignore-not-found deployment $CES_DEPLOMENT_NAME
echo "-------------------------------"
echo ""

echo "[Step 2] Delete RBAC"
kubectl delete --ignore-not-found clusterrolebinding ces-controller
kubectl delete --ignore-not-found clusterrole ces-controller
kubectl -n $K8S_NAMESPACE delete --ignore-not-found sa ces-controller
kubectl -n $CES_NAMESPACE delete --ignore-not-found sa ces-controller
echo "-------------------------------"
echo ""

Expand All @@ -24,11 +25,11 @@ echo "-------------------------------"
echo ""

echo "[Step 4] Delete Secret"
kubectl -n $K8S_NAMESPACE delete --ignore-not-found secret bigip-creds
kubectl -n $CES_NAMESPACE delete --ignore-not-found secret bigip-creds
echo "-------------------------------"
echo ""

echo "[Step 5] Delete ConfigMap"
kubectl -n $K8S_NAMESPACE delete --ignore-not-found cm ces-controller-configmap
kubectl -n $CES_NAMESPACE delete --ignore-not-found cm ces-controller-configmap
echo "-------------------------------"
echo ""
2 changes: 2 additions & 0 deletions doc/zh_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,8 @@ ces-controller-configmap中的参数initialized:
BIGIP_URL: BIG-IP服务的ip
BIGIP_USERNAME: BIG-IP的用户名
BIGIP_INSECURE: BIG-IP的密码
CES_NAMESPACE: 控制器的命名空间
CES_DEPLOMENT_NAME: 控制器应用的名称
```

然后执行install.sh 脚本
Expand Down
6 changes: 3 additions & 3 deletions pkg/as3/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"k8s.io/klog/v2"
)

func InitAs3Tenant(client *Client, filePath string, initialized bool, cesNamespace string) error {
func InitAs3Tenant(client *Client, filePath string, cesNamespace string) error {
config := viper.New()
config.AddConfigPath(filePath)
config.SetConfigName("ces-conf")
Expand Down Expand Up @@ -46,12 +46,12 @@ namespaces:
return fmt.Errorf("No configured Common, please configured, eg: \n%s\n", msg)
}

if getMasterCluster() == GetCluster() && !initialized {
if getMasterCluster() == GetCluster(){
as3Str, err := client.Get(DefaultPartition)
if err != nil {
return fmt.Errorf("failed to get partition, due to: %v", err)
}
if as3Str == "" {
if as3Str == "{}" {
return client.post(initDefaultAS3(), DefaultPartition)
}
}
Expand Down
2 changes: 0 additions & 2 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ import (

const ControllerAgentName = "ces-controller"

const ControllerConfigmap = "ces-controller-configmap"

const (
// SuccessSynced is used as part of the Event 'reason' when a resource is synced
SuccessSynced = "Synced"
Expand Down

0 comments on commit 3152c72

Please sign in to comment.