Skip to content

Commit

Permalink
Merge "[CE-384] Use defualt NFS server for k8s agent"
Browse files Browse the repository at this point in the history
  • Loading branch information
yeasy authored and Gerrit Code Review committed Jun 19, 2018
2 parents 94b0352 + 6555a71 commit d6475e5
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 40 deletions.
1 change: 1 addition & 0 deletions docker-compose-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ services:
expose:
- "8080"
volumes: # This should be removed in product env
- ./src/agent/docker/_compose_files:/cello
- ./src:/app

#TODO: need to follow other images to put at dockerhub
Expand Down
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ services:
- ENABLE_EMAIL_ACTIVE=$ENABLE_EMAIL_ACTIVE
ports:
- "8080:8080"
#volumes:
volumes:
# - ./src:/app
- ./src/agent/docker/_compose_files:/cello

#TODO: need to follow other images to put at dockerhub
user-dashboard:
Expand Down
16 changes: 8 additions & 8 deletions src/agent/k8s/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import sys

from agent import K8sClusterOperation
from agent import KubernetesHost
from agent import KubernetesOperation

sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..'))
from common import log_handler, LOG_LEVEL
Expand Down Expand Up @@ -38,15 +38,15 @@ def _get_cluster_info(self, cid, config):
cluster = ClusterModel.objects.get(id=cid)

cluster_name = cluster.name
kube_config = KubernetesHost().get_kubernets_config(cluster
.host
.k8s_param)
kube_config = KubernetesOperation()._get_config_from_params(cluster
.host
.k8s_param)

clusters_exists = ClusterModel.objects(host=cluster.host)
ports_index = [service.port for service in ServicePort
.objects(cluster__in=clusters_exists)]

nfsServer_ip = cluster.host.k8s_param.get('nfsServer')
nfsServer_ip = cluster.host.k8s_param.get('K8SNfsServer')
consensus = config['consensus_plugin']

return cluster, cluster_name, kube_config, ports_index, \
Expand Down Expand Up @@ -98,9 +98,9 @@ def get_services_urls(self, cid):
cluster = ClusterModel.objects.get(id=cid)

cluster_name = cluster.name
kube_config = KubernetesHost().get_kubernets_config(cluster
.host
.k8s_param)
kube_config = KubernetesOperation()._get_from_params(cluster
.host
.k8s_param)

operation = K8sClusterOperation(kube_config)
services_urls = operation.get_services_urls(cluster_name)
Expand Down
6 changes: 3 additions & 3 deletions src/agent/k8s/cluster_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ def __init__(self, kube_config):

def _upload_config_file(self, cluster_name, consensus):
try:
cluster_path = os.path.join('/opt/share', cluster_name)
cluster_path = os.path.join('/cello', cluster_name)
# Uploading the 'resources' directory with its content in the
# '/opt/share remote directory
# '/cello remote directory
current_path = os.path.dirname(__file__)

# Only solo and kafka supported
Expand All @@ -74,7 +74,7 @@ def _upload_config_file(self, cluster_name, consensus):

def _delete_config_file(self, cluster_name):
try:
cluster_path = os.path.join('/opt/share', cluster_name)
cluster_path = os.path.join('/cello', cluster_name)
shutil.rmtree(cluster_path)
except Exception as e:
error_msg = (
Expand Down
47 changes: 26 additions & 21 deletions src/agent/k8s/host_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import base64
import logging

from common.utils import K8S_CRED_TYPE
from kubernetes import client, config
from common import log_handler, LOG_LEVEL, db, utils

Expand All @@ -27,36 +28,40 @@ def _get_config_from_params(self, k8s_params):
:return: python kubernetes config
"""
k8s_config = client.Configuration()
k8s_config.host = k8s_params.get('address')
k8s_config.host = k8s_params.get('K8SAddress')
if not k8s_config.host.startswith("https://"):
k8s_config.host = "https://" + k8s_config.host

k8s_config.username = k8s_params.get('username')
k8s_config.password = k8s_params.get('password')
if k8s_params.get('K8SCredType') == K8S_CRED_TYPE['account']:
k8s_config.username = k8s_params.get('K8SUsername')
k8s_config.password = k8s_params.get('K8SPassword')

cert_content = base64.decodestring(str.encode(k8s_params.get('cert')))
key_content = base64.decodestring(str.encode(k8s_params.get('key')))
elif k8s_params.get('K8SCredType') == K8S_CRED_TYPE['cert']:
cert_content = \
base64.decodestring(str.encode(k8s_params.get('K8SCert')))
key_content = \
base64.decodestring(str.encode(k8s_params.get('K8SKey')))
k8s_config.cert_file = \
config.kube_config._create_temp_file_with_content(cert_content)
k8s_config.key_file = \
config.kube_config._create_temp_file_with_content(key_content)

k8s_config.cert_file = \
config.kube_config._create_temp_file_with_content(cert_content)

k8s_config.key_file = \
config.kube_config._create_temp_file_with_content(key_content)

config_content = k8s_params.get('config')
# Use config file content to set k8s_config if it exist.
if config_content.strip():
config_file = \
config.kube_config. \
_create_temp_file_with_content(config_content)
elif k8s_params.get('K8SCredType') == K8S_CRED_TYPE['config']:
config_content = k8s_params.get('K8SConfig')

if config_content.strip():
config_file = \
config.kube_config. \
_create_temp_file_with_content(config_content)

loader = \
config.kube_config. \
_get_kube_config_loader_for_yaml_file(config_file)
loader = \
config.kube_config. \
_get_kube_config_loader_for_yaml_file(config_file)

loader.load_and_set(k8s_config)
loader.load_and_set(k8s_config)

if k8s_params.get('use_ssl') == "false":
if k8s_params.get('K8SUseSsl') == "false":
k8s_config.verify_ssl = False
else:
k8s_config.verify_ssl = True
Expand Down
2 changes: 1 addition & 1 deletion src/agent/k8s/templates/fabric-1-0-explorer.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ spec:
namespace: {{clusterName}}
name: {{clusterName}}-explorer-pvc
nfs:
path: /opt/share/{{clusterName}}/resources/
path: /cello/{{clusterName}}/resources/
server: {{nfsServer}} # change to your nfs server ip here.
---

Expand Down
2 changes: 1 addition & 1 deletion src/agent/k8s/templates/orderer0.ordererorg.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ spec:
- name: certificate
persistentVolumeClaim:
claimName: {{clusterName}}-ordererorg-pvc
#path: /opt/share
#path: /cello
#persistentVolumeClaim:
# claimName: nfs

Expand Down
2 changes: 1 addition & 1 deletion src/agent/k8s/templates/ordererorg-pvc.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ spec:
namespace: {{clusterName}}
name: {{clusterName}}-ordererorg-pvc
nfs:
path: /opt/share/{{clusterName}}/resources/crypto-config/ordererOrganizations/ordererorg
path: /cello/{{clusterName}}/resources/crypto-config/ordererOrganizations/ordererorg
server: {{nfsServer}} #change to your nfs server ip here

---
Expand Down
2 changes: 1 addition & 1 deletion src/agent/k8s/templates/org1-cli.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ spec:
namespace: {{clusterName}}
name: {{clusterName}}-org1-resources-pvc
nfs:
path: /opt/share/{{clusterName}}/resources
path: /cello/{{clusterName}}/resources
server: {{nfsServer}} # change to your nfs server ip here.
---

Expand Down
2 changes: 1 addition & 1 deletion src/agent/k8s/templates/org1-pvc.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ spec:
namespace: {{clusterName}}
name: {{clusterName}}-org1-pvc
nfs:
path: /opt/share/{{clusterName}}/resources/crypto-config/peerOrganizations/org1
path: /cello/{{clusterName}}/resources/crypto-config/peerOrganizations/org1
server: {{nfsServer}} #change to your nfs server ip here

---
Expand Down
2 changes: 1 addition & 1 deletion src/agent/k8s/templates/org2-cli.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ spec:
namespace: {{clusterName}}
name: {{clusterName}}-org2-resources-pvc
nfs:
path: /opt/share/{{clusterName}}/resources
path: /cello/{{clusterName}}/resources
server: {{nfsServer}} # change to your nfs server ip here.
---

Expand Down
2 changes: 1 addition & 1 deletion src/agent/k8s/templates/org2-pvc.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ spec:
namespace: {{clusterName}}
name: {{clusterName}}-org2-pvc
nfs:
path: /opt/share/{{clusterName}}/resources/crypto-config/peerOrganizations/org2
path: /cello/{{clusterName}}/resources/crypto-config/peerOrganizations/org2
server: {{nfsServer}} #change to your nfs server ip here

---
Expand Down

0 comments on commit d6475e5

Please sign in to comment.