[ Cmii ] [ Octopus ] - add tcp portforwarding part
This commit is contained in:
@@ -1,120 +0,0 @@
|
||||
package cmii_operator
|
||||
|
||||
const cmiiBackendDeploymentTemplate = `
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: {{ .AppName }}
|
||||
namespace: {{ .Namespace }}
|
||||
labels:
|
||||
cmii.type: backend
|
||||
cmii.app: {{ .AppName }}
|
||||
octopus/control: backend-app-1.0.0
|
||||
app.kubernetes.io/managed-by: octopus/control
|
||||
app.kubernetes.io/app-version: {{ .TagVersion }}
|
||||
spec:
|
||||
replicas: {{ .Replicas }}
|
||||
strategy:
|
||||
rollingUpdate:
|
||||
maxUnavailable: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
cmii.type: backend
|
||||
cmii.app: {{ .AppName }}
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
cmii.type: backend
|
||||
cmii.app: {{ .AppName }}
|
||||
spec:
|
||||
affinity:
|
||||
nodeAffinity:
|
||||
requiredDuringSchedulingIgnoredDuringExecution:
|
||||
nodeSelectorTerms:
|
||||
- matchExpressions:
|
||||
- key: uavcloud.env
|
||||
operator: In
|
||||
values:
|
||||
- demo
|
||||
imagePullSecrets:
|
||||
- name: harborsecret
|
||||
containers:
|
||||
- name: {{ .AppName }}
|
||||
image: "harbor.cdcyy.com.cn/cmii/{{ .AppName }}:{{ .ImageTag }}"
|
||||
imagePullPolicy: Always
|
||||
env:
|
||||
- name: K8S_NAMESPACE
|
||||
value: "{{ .Namespace }}"
|
||||
- name: APPLICATION_NAME
|
||||
value: "{{ .AppName }}"
|
||||
- name: CUST_JAVA_OPTS
|
||||
value: "-Xms500m -Xmx1500m -Dlog4j2.formatMsgNoLookups=true"
|
||||
- name: NACOS_REGISTRY
|
||||
value: "helm-nacos:8848"
|
||||
- name: NACOS_DISCOVERY_IP
|
||||
valueFrom:
|
||||
fieldRef:
|
||||
fieldPath: status.podIP
|
||||
- name: NACOS_DISCOVERY_PORT
|
||||
value: "8080"
|
||||
- name: BIZ_CONFIG_GROUP
|
||||
value: {{ .TagVersion }}
|
||||
- name: SYS_CONFIG_GROUP
|
||||
value: {{ .TagVersion }}
|
||||
- name: IMAGE_VERSION
|
||||
value: {{ .TagVersion }}
|
||||
- name: NACOS_USERNAME
|
||||
value: "developer"
|
||||
- name: NACOS_PASSWORD
|
||||
value: "Deve@9128201"
|
||||
ports:
|
||||
- name: pod-port
|
||||
containerPort: 8080
|
||||
protocol: TCP
|
||||
resources:
|
||||
limits:
|
||||
memory: 2Gi
|
||||
cpu: 2
|
||||
requests:
|
||||
memory: 1Gi
|
||||
cpu: 200m
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /cmii/ping
|
||||
port: pod-port
|
||||
scheme: HTTP
|
||||
initialDelaySeconds: 60
|
||||
timeoutSeconds: 5
|
||||
periodSeconds: 20
|
||||
successThreshold: 1
|
||||
failureThreshold: 3
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /cmii/ping
|
||||
port: pod-port
|
||||
scheme: HTTP
|
||||
initialDelaySeconds: 60
|
||||
timeoutSeconds: 5
|
||||
periodSeconds: 20
|
||||
successThreshold: 1
|
||||
failureThreshold: 3
|
||||
startupProbe:
|
||||
httpGet:
|
||||
path: /cmii/ping
|
||||
port: pod-port
|
||||
scheme: HTTP
|
||||
initialDelaySeconds: 60
|
||||
timeoutSeconds: 3
|
||||
periodSeconds: 20
|
||||
successThreshold: 1
|
||||
failureThreshold: 5
|
||||
volumeMounts:
|
||||
- name: glusterfs-backend-log-volume
|
||||
mountPath: /cmii/logs
|
||||
readOnly: false
|
||||
subPath: {{ .Namespace }}/{{ .AppName }}
|
||||
volumes:
|
||||
- name: glusterfs-backend-log-volume
|
||||
persistentVolumeClaim:
|
||||
claimName: glusterfs-backend-log-pvc
|
||||
`
|
||||
@@ -1,17 +0,0 @@
|
||||
package cmii_operator
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestCmiiBackendDeploymentConfig_ParseToApplyConf(t *testing.T) {
|
||||
|
||||
deploymentConfig := CmiiBackendDeploymentConfig{
|
||||
Namespace: "uavcloud-dev",
|
||||
AppName: "cmii-uav-gateway",
|
||||
ImageTag: "5.2.0-123",
|
||||
TagVersion: "5.2.0",
|
||||
Replicas: "2",
|
||||
}
|
||||
|
||||
deploymentConfig.ParseToApplyConf()
|
||||
|
||||
}
|
||||
@@ -161,8 +161,7 @@ func (op *CmiiK8sOperator) DeploymentAll(cmiiEnv string) []v1.Deployment {
|
||||
length := len(deployments)
|
||||
log.InfoF("[DeploymentAll] - deployment in [%s] count is => %d", op.CurrentNamespace, length)
|
||||
results := make([]v1.Deployment, length)
|
||||
//var results []v1.Deployment
|
||||
//ccc := make(chan v1.Deployment, length)
|
||||
ccc := make(chan v1.Deployment, length)
|
||||
var wg sync.WaitGroup
|
||||
//var mutex sync.Mutex
|
||||
|
||||
@@ -193,32 +192,34 @@ func (op *CmiiK8sOperator) DeploymentAll(cmiiEnv string) []v1.Deployment {
|
||||
|
||||
go func(deploymentList []v1.Deployment, start int, results *[]v1.Deployment) {
|
||||
|
||||
for index, deployment := range deploymentList {
|
||||
for _, deployment := range deploymentList {
|
||||
objectMeta := deployment.ObjectMeta
|
||||
objectMeta.SetAnnotations(nil)
|
||||
objectMeta.SetManagedFields(nil)
|
||||
deployment.ObjectMeta = objectMeta
|
||||
|
||||
//ccc <- deployment
|
||||
i := *results
|
||||
i[index+start] = deployment
|
||||
ccc <- deployment
|
||||
//i := *results
|
||||
//i[index+start] = deployment
|
||||
}
|
||||
|
||||
wg.Done()
|
||||
}(deployments[start:end], start, &results)
|
||||
}
|
||||
|
||||
//go func() {
|
||||
// wg.Wait()
|
||||
// close(ccc)
|
||||
//}()
|
||||
go func() {
|
||||
wg.Wait()
|
||||
close(ccc)
|
||||
}()
|
||||
|
||||
wg.Wait()
|
||||
//for deployment := range ccc {
|
||||
// results = append(results, deployment)
|
||||
//}
|
||||
index := 0
|
||||
for deployment := range ccc {
|
||||
results[index] = deployment
|
||||
index++
|
||||
}
|
||||
|
||||
return results
|
||||
return results[:index]
|
||||
}
|
||||
|
||||
func (op *CmiiK8sOperator) DeploymentAllInterface(cmiiEnv string) []CmiiDeploymentInterface {
|
||||
|
||||
@@ -38,5 +38,7 @@ func main() {
|
||||
}
|
||||
|
||||
// restart all backend
|
||||
cmii_operator.RestartCmiiBackendDeployment(realNamespace)
|
||||
cmii_operator.RestartCmiiFrontendDeployment(realNamespace)
|
||||
|
||||
}
|
||||
|
||||
@@ -1,25 +1,47 @@
|
||||
package cmii_operator
|
||||
package deploy
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
v1 "k8s.io/api/apps/v1"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
appsv1 "k8s.io/client-go/applyconfigurations/apps/v1"
|
||||
"sigs.k8s.io/yaml"
|
||||
"text/template"
|
||||
"wdd.io/agent-go/utils"
|
||||
)
|
||||
|
||||
type CommonEnvironmentConfig struct {
|
||||
WebIP string
|
||||
WebPort string
|
||||
HarborIP string
|
||||
HarborPort string
|
||||
}
|
||||
|
||||
type CmiiBackendDeploymentConfig struct {
|
||||
Namespace string
|
||||
AppName string
|
||||
ImageTag string
|
||||
TagVersion string
|
||||
Replicas string
|
||||
NodePort string
|
||||
NeedPvcCache bool
|
||||
CustomJvmOpt string
|
||||
}
|
||||
|
||||
type CmiiFrontendDeploymentConfig struct {
|
||||
Namespace string
|
||||
AppName string
|
||||
ImageTag string
|
||||
TagVersion string
|
||||
Replicas string
|
||||
ShortName string
|
||||
}
|
||||
|
||||
func (backend CmiiBackendDeploymentConfig) ParseToApplyConf() *appsv1.DeploymentApplyConfiguration {
|
||||
|
||||
// 解析模板
|
||||
|
||||
tmpl, err := template.New("cmiiBackendDeploymentTemplate").Parse(cmiiBackendDeploymentTemplate)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -41,5 +63,28 @@ func (backend CmiiBackendDeploymentConfig) ParseToApplyConf() *appsv1.Deployment
|
||||
|
||||
utils.BeautifulPrint(&deployment)
|
||||
|
||||
// service
|
||||
parse, err := template.New("cmiiBackendServiceTemplate").Parse(cmiiBackendServiceTemplate)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// 应用数据并打印结果
|
||||
var resulta bytes.Buffer
|
||||
err = parse.Execute(&resulta, backend)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(resulta.String())
|
||||
|
||||
// 创建Deployment对象
|
||||
service := corev1.Service{}
|
||||
err = yaml.Unmarshal(resulta.Bytes(), &service)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
utils.BeautifulPrint(&service)
|
||||
|
||||
return nil
|
||||
}
|
||||
263
cmii_operator/deploy/CmiiAppDeployTemplate.go
Normal file
263
cmii_operator/deploy/CmiiAppDeployTemplate.go
Normal file
@@ -0,0 +1,263 @@
|
||||
package deploy
|
||||
|
||||
const cmiiBackendDeploymentTemplate = `
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: {{ .AppName }}
|
||||
namespace: {{ .Namespace }}
|
||||
labels:
|
||||
cmii.type: backend
|
||||
cmii.app: {{ .AppName }}
|
||||
octopus/control: backend-app-1.0.0
|
||||
app.kubernetes.io/managed-by: octopus/control
|
||||
app.kubernetes.io/app-version: {{ .TagVersion }}
|
||||
spec:
|
||||
replicas: {{ .Replicas }}
|
||||
strategy:
|
||||
rollingUpdate:
|
||||
maxUnavailable: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
cmii.type: backend
|
||||
cmii.app: {{ .AppName }}
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
cmii.type: backend
|
||||
cmii.app: {{ .AppName }}
|
||||
spec:
|
||||
affinity:
|
||||
nodeAffinity:
|
||||
requiredDuringSchedulingIgnoredDuringExecution:
|
||||
nodeSelectorTerms:
|
||||
- matchExpressions:
|
||||
- key: uavcloud.env
|
||||
operator: In
|
||||
values:
|
||||
- demo
|
||||
imagePullSecrets:
|
||||
- name: harborsecret
|
||||
containers:
|
||||
- name: {{ .AppName }}
|
||||
image: "harbor.cdcyy.com.cn/cmii/{{ .AppName }}:{{ .ImageTag }}"
|
||||
imagePullPolicy: Always
|
||||
env:
|
||||
- name: K8S_NAMESPACE
|
||||
value: {{ .Namespace }}
|
||||
- name: APPLICATION_NAME
|
||||
value: {{ .AppName }}
|
||||
- name: CUST_JAVA_OPTS
|
||||
value: "-Xms500m -Xmx1500m -Dlog4j2.formatMsgNoLookups=true"
|
||||
- name: NACOS_REGISTRY
|
||||
value: "helm-nacos:8848"
|
||||
- name: NACOS_DISCOVERY_IP
|
||||
valueFrom:
|
||||
fieldRef:
|
||||
fieldPath: status.podIP
|
||||
- name: NACOS_DISCOVERY_PORT
|
||||
value: "8080"
|
||||
- name: BIZ_CONFIG_GROUP
|
||||
value: {{ .TagVersion }}
|
||||
- name: SYS_CONFIG_GROUP
|
||||
value: {{ .TagVersion }}
|
||||
- name: IMAGE_VERSION
|
||||
value: {{ .TagVersion }}
|
||||
- name: NACOS_USERNAME
|
||||
value: "developer"
|
||||
- name: NACOS_PASSWORD
|
||||
value: "Deve@9128201"
|
||||
ports:
|
||||
- name: pod-port
|
||||
containerPort: 8080
|
||||
protocol: TCP
|
||||
resources:
|
||||
limits:
|
||||
memory: 2Gi
|
||||
cpu: 2
|
||||
requests:
|
||||
memory: 1Gi
|
||||
cpu: 200m
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /cmii/ping
|
||||
port: pod-port
|
||||
scheme: HTTP
|
||||
initialDelaySeconds: 60
|
||||
timeoutSeconds: 5
|
||||
periodSeconds: 20
|
||||
successThreshold: 1
|
||||
failureThreshold: 3
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /cmii/ping
|
||||
port: pod-port
|
||||
scheme: HTTP
|
||||
initialDelaySeconds: 60
|
||||
timeoutSeconds: 5
|
||||
periodSeconds: 20
|
||||
successThreshold: 1
|
||||
failureThreshold: 3
|
||||
startupProbe:
|
||||
httpGet:
|
||||
path: /cmii/ping
|
||||
port: pod-port
|
||||
scheme: HTTP
|
||||
initialDelaySeconds: 60
|
||||
timeoutSeconds: 3
|
||||
periodSeconds: 20
|
||||
successThreshold: 1
|
||||
failureThreshold: 5
|
||||
volumeMounts:
|
||||
- name: glusterfs-backend-log-volume
|
||||
mountPath: /cmii/logs
|
||||
readOnly: false
|
||||
subPath: {{ .Namespace }}/{{ .AppName }}
|
||||
{{- if .NeedPvcCache }}
|
||||
- name: data-cache-volume
|
||||
mountPath: /cmii/cache
|
||||
readOnly: false
|
||||
subPath: {{ .Namespace }}/{{ .AppName }}
|
||||
{{- end }}
|
||||
volumes:
|
||||
- name: glusterfs-backend-log-volume
|
||||
persistentVolumeClaim:
|
||||
claimName: glusterfs-backend-log-pvc
|
||||
{{- if .NeedPvcCache }}
|
||||
- name: data-cache-volume
|
||||
persistentVolumeClaim:
|
||||
claimName: {{ .AppName }}-cache
|
||||
{{- end }}
|
||||
`
|
||||
|
||||
const cmiiBackendServiceTemplate = `
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: {{ .AppName }}
|
||||
namespace: {{ .Namespace }}
|
||||
labels:
|
||||
cmii.type: backend
|
||||
cmii.app: {{ .AppName }}
|
||||
octopus/control: backend-app-1.0.0
|
||||
app.kubernetes.io/managed-by: octopus/control
|
||||
app.kubernetes.io/app-version: {{ .TagVersion }}
|
||||
spec:
|
||||
{{- if .NodePort }}
|
||||
type: NodePort
|
||||
{{- else }}
|
||||
type: ClusterIP
|
||||
{{- end }}
|
||||
selector:
|
||||
cmii.type: backend
|
||||
cmii.app: {{ .AppName }}
|
||||
ports:
|
||||
- name: backend-tcp
|
||||
port: 8080
|
||||
protocol: TCP
|
||||
targetPort: 8080
|
||||
{{- if .NodePort }}
|
||||
nodePort: {{ .NodePort }}
|
||||
{{- end }}
|
||||
`
|
||||
const cmiiBackendPVCTemplate = `
|
||||
apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
name: {{ .AppName }}-cache
|
||||
namespace: {{ .Namespace }}
|
||||
labels:
|
||||
cmii.type: backend
|
||||
cmii.app: {{ .AppName }}
|
||||
octopus/control: backend-app-1.0.0
|
||||
app.kubernetes.io/managed-by: octopus/control
|
||||
app.kubernetes.io/app-version: {{ .TagVersion }}
|
||||
spec:
|
||||
storageClassName: nfs-prod-distribute
|
||||
accessModes:
|
||||
- ReadWriteMany
|
||||
volumeMode: Filesystem
|
||||
resources:
|
||||
requests:
|
||||
storage: 15Gi
|
||||
`
|
||||
|
||||
const cmiiFrontendDeploymentTemplate = `
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: {{ .AppName }}
|
||||
namespace: {{ .Namespace }}
|
||||
labels:
|
||||
cmii.type: frontend
|
||||
cmii.app: {{ .AppName }}
|
||||
octopus/control: frontend-app-1.0.0
|
||||
app.kubernetes.io/managed-by: octopus/control
|
||||
app.kubernetes.io/app-version: {{ .TagVersion }}
|
||||
spec:
|
||||
replicas: {{ .Replicas }}
|
||||
strategy:
|
||||
rollingUpdate:
|
||||
maxUnavailable: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
cmii.type: frontend
|
||||
cmii.app: {{ .AppName }}
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
cmii.type: frontend
|
||||
cmii.app: {{ .AppName }}
|
||||
spec:
|
||||
imagePullSecrets:
|
||||
- name: harborsecret
|
||||
containers:
|
||||
- name: {{ .AppName }}
|
||||
image: "harbor.cdcyy.com.cn/cmii/{{ .AppName }}:{{ .ImageTag }}"
|
||||
imagePullPolicy: Always
|
||||
env:
|
||||
- name: K8S_NAMESPACE
|
||||
value: {{ .Namespace }}
|
||||
- name: APPLICATION_NAME
|
||||
value: {{ .AppName }}
|
||||
ports:
|
||||
- name: platform-9528
|
||||
containerPort: 9528
|
||||
protocol: TCP
|
||||
resources:
|
||||
limits:
|
||||
cpu: "1"
|
||||
memory: 1Gi
|
||||
requests:
|
||||
cpu: 500m
|
||||
memory: 500Mi
|
||||
volumeMounts:
|
||||
- name: nginx-conf
|
||||
mountPath: /usr/local/nginx/conf/nginx.conf
|
||||
subPath: nginx.conf
|
||||
- name: default-nginx-conf
|
||||
mountPath: /etc/nginx/conf.d/default.conf
|
||||
subPath: default.conf
|
||||
- name: tenant-prefix
|
||||
subPath: ingress-config.js
|
||||
mountPath: /home/cmii-platform/dist/ingress-config.js
|
||||
volumes:
|
||||
- name: nginx-conf
|
||||
configMap:
|
||||
name: nginx-cm
|
||||
items:
|
||||
- key: nginx.conf
|
||||
path: nginx.conf
|
||||
- name: default-nginx-conf
|
||||
configMap:
|
||||
name: default-nginx-cm
|
||||
items:
|
||||
- key: default.conf
|
||||
path: default.conf
|
||||
- name: tenant-prefix
|
||||
configMap:
|
||||
name: tenant-prefix-{{ .ShortName }}
|
||||
items:
|
||||
- key: ingress-config.js
|
||||
path: ingress-config.js
|
||||
`
|
||||
19
cmii_operator/deploy/CmiiAppDeploy_test.go
Normal file
19
cmii_operator/deploy/CmiiAppDeploy_test.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package deploy
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestCmiiBackendDeploymentConfig_ParseToApplyConf(t *testing.T) {
|
||||
|
||||
deploymentConfig := CmiiBackendDeploymentConfig{
|
||||
Namespace: "uavcloud-dev",
|
||||
AppName: "cmii-uav-gateway",
|
||||
ImageTag: "5.2.0-123",
|
||||
TagVersion: "5.2.0",
|
||||
Replicas: "2",
|
||||
NodePort: "31213",
|
||||
NeedPvcCache: true,
|
||||
}
|
||||
|
||||
deploymentConfig.ParseToApplyConf()
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user