Commit 680614ef by Cheng-En Wu

fix canary release attr

parent 66b16ba6
Pipeline #750 failed with stages
stages:
- build
- deploy
build:
image: docker:stable-dind
stage: build
script:
- git clone https://gitlab.com/cewuandy/auto_istio
- cd auto_istio
- docker login registry.gitlab.com
- docker build -t registry.gitlab.com/cewuandy/auto_istio .
- docker push registry.gitlab.com/cewuandy/auto_istio
environment:
name: test_abc
deploy:
image: bitnami/kubectl:latest
stage: deploy
script:
- export KUBE_CONFIG=$CONFIG_FILE
- git clone https://gitlab.com/cewuandy/auto_istio
- cd auto_istio
- kubectl apply -f auto_istio.yaml
......@@ -14,7 +14,7 @@
</component>
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="Remote Python 3.6.9 (sftp://ubuntu@10.0.0.210:22/usr/bin/python3)" jdkType="Python SDK" />
<orderEntry type="jdk" jdkName="Remote Python 3.6.9 (sftp://ubuntu@192.168.2.21:22/usr/bin/python3)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TemplatesService">
......@@ -25,7 +25,4 @@
</list>
</option>
</component>
<component name="TestRunnerService">
<option name="PROJECT_TEST_RUNNER" value="Unittests" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="PublishConfigData" autoUpload="Always" serverName="ubuntu@10.0.0.210:22" autoUploadExternalChanges="true">
<component name="PublishConfigData" autoUpload="Always" serverName="B3-1" autoUploadExternalChanges="true" showAutoUploadSettingsWarning="false">
<serverData>
<paths name="10.0.0.210">
<serverdata>
<mappings>
<mapping local="$PROJECT_DIR$" web="/" />
</mappings>
</serverdata>
</paths>
<paths name="10.0.0.232">
<serverdata>
<mappings>
<mapping deploy="/home/ubuntu/auto_istio" local="$PROJECT_DIR$" />
</mappings>
</serverdata>
</paths>
<paths name="Copy of project-level server '10.0.0.210'">
<paths name="B3-1">
<serverdata>
<mappings>
<mapping deploy="/home/ubuntu/auto_istio" local="$PROJECT_DIR$" />
</mappings>
</serverdata>
</paths>
<paths name="ubuntu@10.0.0.210:22">
<paths name="b3-1">
<serverdata>
<mappings>
<mapping deploy="/home/ubuntu/auto_istio" local="$PROJECT_DIR$" />
<mapping deploy="/home/ubuntu/auto_istio" local="$PROJECT_DIR$" web="/" />
</mappings>
</serverdata>
</paths>
......
......@@ -3,7 +3,7 @@
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Remote Python 3.6.9 (sftp://ubuntu@10.0.0.210:22/usr/bin/python3)" project-jdk-type="Python SDK" />
<component name="ProjectRootManager" version="2" project-jdk-name="Remote Python 3.6.9 (sftp://ubuntu@192.168.2.21:22/usr/bin/python3)" project-jdk-type="Python SDK" />
<component name="PyPackaging">
<option name="earlyReleasesAsUpgrades" value="true" />
</component>
......
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="SshConfigs">
<configs>
<sshConfig host="10.0.0.210" id="f2d64377-7ace-4838-ac83-7f66af570ffa" keyPath="C:\Users\Administrator\.ssh\id_rsa" port="22" customName="10.0.0.210" nameFormat="CUSTOM" />
<sshConfig host="10.0.0.210" id="8e8098ea-dd0e-4eff-a2c2-8ce799e84bba" keyPath="C:\Users\Administrator\.ssh\id_rsa" port="22" customName="10.0.0.210" nameFormat="CUSTOM" />
<sshConfig host="10.0.0.210" id="b714a8dd-91af-42b8-8492-836471e31607" keyPath="C:\Users\Administrator\.ssh\id_rsa" port="22" customName="10.0.0.210" nameFormat="CUSTOM" />
<sshConfig host="10.0.0.210" id="2ac788c2-67d4-4d20-ac53-415d08ce1542" keyPath="C:\Users\Administrator\.ssh\id_rsa" port="22" customName="10.0.0.210" nameFormat="CUSTOM" />
<sshConfig host="10.0.0.210" id="9471231d-b032-4b54-b64d-bb2ad6fba4cc" keyPath="C:\Users\Administrator\.ssh\id_rsa" port="22" customName="10.0.0.210" nameFormat="CUSTOM" />
<sshConfig host="10.0.0.210" id="bef5254c-7c4b-4edb-90ac-a41f04b0c4a4" keyPath="C:\Users\Administrator\.ssh\id_rsa" port="22" customName="10.0.0.210" nameFormat="CUSTOM" />
<sshConfig host="10.0.0.210" id="f1bb479e-0d00-446b-b914-b5c9efc77162" keyPath="C:\Users\Administrator\.ssh\id_rsa" port="22" customName="10.0.0.210" nameFormat="CUSTOM" />
<sshConfig host="10.0.0.210" id="2caf8e1f-253a-460c-8f71-49200d644b85" keyPath="C:\Users\Administrator\.ssh\id_rsa" port="22" customName="10.0.0.210" nameFormat="CUSTOM" />
<sshConfig host="10.0.0.210" id="f8198786-579b-4a3b-a023-6effff7823a1" keyPath="C:\Users\Administrator\.ssh\id_rsa" port="22" customName="10.0.0.210" nameFormat="CUSTOM" />
<sshConfig host="10.0.0.210" id="3cb4b2ba-367b-46a0-84d2-1e74fa89870f" keyPath="C:\Users\Administrator\.ssh\id_rsa" port="22" customName="10.0.0.210" nameFormat="CUSTOM" />
<sshConfig host="10.0.0.210" id="9d47fb10-d0f6-42d0-8e67-d00673795a7a" keyPath="C:\Users\Administrator\.ssh\id_rsa" port="22" customName="10.0.0.210" nameFormat="CUSTOM" />
</configs>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
......@@ -2,12 +2,11 @@
<project version="4">
<component name="WebServers">
<option name="servers">
<webServer id="c002f63c-1771-45e0-8b53-606c3605ea1f" name="10.0.0.210" url="http://10.0.0.210">
<fileTransfer host="10.0.0.210" port="22" privateKey="C:\Users\Administrator\.ssh\id_rsa" accessType="SFTP" keyPair="true">
<webServer id="5a3ac861-af56-4907-a166-b4db915d4229" name="b3-1" url="http://0.0.0.0">
<fileTransfer accessType="SFTP" host="10.0.0.210" port="22" sshConfigId="1d66578f-5d5c-42a4-86b7-fbeb0accbb24" sshConfig="B3-1" keyPair="true">
<advancedOptions>
<advancedOptions dataProtectionLevel="Private" passiveMode="true" shareSSLContext="true" />
</advancedOptions>
<option name="port" value="22" />
</fileTransfer>
</webServer>
</option>
......
FROM ubuntu:16.04
RUN apt update && apt install -y libssl-dev python3 python3-pip git libmysqlclient-dev
WORKDIR /
RUN git clone https://github.com/free5gmano/free5gmano.git
RUN pip3 install -r requirements.txt
CMD python3 manage.py makemigrations && python3 manage.py migrate && python3 manage.py runserver 0.0.0.0:8000
\ No newline at end of file
eyJhbGciOiJSUzI1NiIsImtpZCI6IiJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJkZWZhdWx0Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZWNyZXQubmFtZSI6ImRlZmF1bHQtdG9rZW4tZG5yN2giLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoiZGVmYXVsdCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50LnVpZCI6ImE5N2MwNzI4LWJiNGYtNGE1Yy1hM2RmLThlOWZmZmI5ZGI1ZSIsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDpkZWZhdWx0OmRlZmF1bHQifQ.kp5xdj7cqNzGKSY-j1gBitP-Rr_90bz92B_FF91NipPGFE6f9BwQtZD9eYcMCCVnyvthDALO4egh-FJuLle9KT-EdcWsF58LFklBIzbFiSgF4gj5DgXbNhu5P9ykuhng-qJMl21h1yBD6YUHmEB7yU05gOjNgg_4MjaCI4dKo7fPEthaLJygqsXjMksH3af4ss6F2XUGTC9WmB6jdjTAzUR83lzMjoF6I8Lkc5Xzj595iRXL7KZeCLyTD8mR5EcE3weThOSayWNzZHckwgOV-_qp1_o-O6Ujl4Ga7NeNhCZI49jgMSxnkbM4qIavP_FO05nfmbMWUj1UfGy6ilkFoA
\ No newline at end of file
......@@ -16,9 +16,10 @@ from rest_framework.decorators import action
from rest_framework.parsers import JSONParser
from rest_framework.viewsets import ModelViewSet
host = "https://10.0.0.210:6443/"
dr_url = "apis/networking.istio.io/v1alpha3/namespaces/default/destinationrules/"
vs_url = "apis/networking.istio.io/v1alpha3/namespaces/default/virtualservices/"
config.load_kube_config()
host = client.CoreV1Api().api_client.configuration.host
dr_url = "/apis/networking.istio.io/v1alpha3/namespaces/default/destinationrules/"
vs_url = "/apis/networking.istio.io/v1alpha3/namespaces/default/virtualservices/"
class AutoIstioApi(ModelViewSet):
......@@ -58,7 +59,6 @@ class AutoIstioApi(ModelViewSet):
config.kube_config.load_kube_config()
v1 = client.CoreV1Api()
v1beta1 = client.ExtensionsV1beta1Api()
service = v1.read_namespaced_service(name=request_data['host'], namespace='default')
pod_ret = v1.list_namespaced_pod(namespace='default',
......@@ -180,7 +180,41 @@ class PodInfo:
def get_token():
config.load_kube_config()
v1 = client.CoreV1Api()
secret = v1.read_namespaced_secret(namespace='default', name="default-token-dnr7h")
rbac_v1 = client.RbacAuthorizationV1Api()
try:
v1.read_namespace(name="auto-istio", pretty=True)
except client.rest.ApiException:
metadata = {"name": "auto-istio"}
namespace = client.V1Namespace(api_version="v1", kind="Namespace",
metadata=metadata)
v1.create_namespace(namespace)
try:
rbac_v1.read_cluster_role_binding(name="auto_istio_binding", pretty=True)
except client.rest.ApiException:
metadata = {"name": "auto_istio_binding"}
subjects = [
{
"kind": "ServiceAccount",
"name": "default",
"namespace": "auto-istio"
}
]
role_ref = {
"kind": "ClusterRole",
"name": "cluster-admin",
"apiGroup": "rbac.authorization.k8s.io"
}
cluster_role_binding = client.V1ClusterRoleBinding(
api_version="rbac.authorization.k8s.io/v1",
kind="ClusterRoleBinding",
metadata=metadata,
subjects=subjects,
role_ref=role_ref)
rbac_v1.create_cluster_role_binding(cluster_role_binding)
service_account = v1.read_namespaced_service_account(namespace="auto-istio", name="default")
secret = v1.read_namespaced_secret(namespace='auto-istio', name=service_account.secrets[0].name)
return base64.b64decode(secret.data['token']).decode("utf-8")
......@@ -223,10 +257,11 @@ def create_traffic_shifting_vs(request_data, sorted_version, new_version_weight)
def canary_release_threading(request_data, new_pod_name, new_pod_timestamp, sorted_version):
print("threading start")
v1 = client.CoreV1Api()
v1beta1 = client.ExtensionsV1beta1Api()
successes = 0
while successes < 10:
while successes < request_data['mirroringSucceedTimes']:
successes = 0
failed = 0
now_time = datetime.datetime.now()
......@@ -244,7 +279,7 @@ def canary_release_threading(request_data, new_pod_name, new_pod_timestamp, sort
start_mark = re.compile(
'^\\[([0-9]+)-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])[Tt]([01][0-9]|2[0-3]):'
'([0-5][0-9]):([0-5][0-9]|60)(\\.[0-9]+)?(([Zz])|([+|-]([01][0-9]|2[0-3]):'
'[0-5][0-9]))\\]$')
'[0-5][0-9]))\\]$') # Log Header
line_list = line.split(" ")
if start_mark.match(line_list[0]):
if http_2xx_pattern.match(line_list[4]):
......@@ -270,11 +305,11 @@ def canary_release_threading(request_data, new_pod_name, new_pod_timestamp, sort
new_deployment.spec.replicas = old_deployment.spec.replicas
v1beta1.patch_namespaced_deployment(new_deployment.metadata.name, "default", new_deployment)
time.sleep(10)
for i in range(101):
print(i)
create_traffic_shifting_vs(request_data, sorted_version, i)
time.sleep(1)
for i in range(0, int(100 / request_data['trafficShiftingPercent']), 1):
create_traffic_shifting_vs(request_data,
sorted_version,
(i + 1) * request_data['trafficShiftingPercent'])
time.sleep(request_data['trafficShiftingPerSecond'])
old_deployment.spec.replicas = 0
v1beta1.patch_namespaced_deployment(old_deployment.metadata.name, "default", old_deployment)
......
apiVersion: apps/v1
kind: Deployment
metadata:
name: auto_istio
namespace: auto-istio
spec:
selector:
matchLabels:
app: auto_istio
replicas: 1
template:
metadata:
labels:
app: auto_istio
spec:
containers:
- name: auto_istio
image: registry.gitlab.com/cewuandy/auto_istio
imagePullPolicy: Always
---
apiVersion: v1
kind: Service
metadata:
name: auto_istio
spec:
type: ClusterIP
ports:
- name: api-server
port: 8000
selector:
app: auto_istio
......@@ -28,8 +28,7 @@ urlpatterns = [
url(r'^istio/canary_release',
AutoIstioApi.as_view({
'post': 'create_canary_release'})),
url(r'^istio/retries',
url(r'^istio/retry_policy',
AutoIstioApi.as_view({
'post': 'create_retry_policy'}))
]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment