Added vagrant install file
Change-Id: Ib784ff13474c4e21a5349a3c7e6d27ed9597adca
diff --git a/rapp-manager/config/application.yaml b/rapp-manager/config/application.yaml
index fef0225..e23b8dd 100644
--- a/rapp-manager/config/application.yaml
+++ b/rapp-manager/config/application.yaml
@@ -43,7 +43,7 @@
org.springframework: ERROR
org.springframework.data: ERROR
org.springframework.web.reactive.function.client.ExchangeFunctions: ERROR
- org.oransc.rappmanager: INFO
+ org.oransc.rappmanager: DEBUG
file:
name: /var/log/rapp-manager/application.log
app:
diff --git a/rapp-manager/src/main/java/org/oransc/rappmanager/helm/HelmClient.java b/rapp-manager/src/main/java/org/oransc/rappmanager/helm/HelmClient.java
index dce6d30..05a8e00 100644
--- a/rapp-manager/src/main/java/org/oransc/rappmanager/helm/HelmClient.java
+++ b/rapp-manager/src/main/java/org/oransc/rappmanager/helm/HelmClient.java
@@ -18,6 +18,7 @@
package org.oransc.rappmanager.helm;
+import java.lang.invoke.MethodHandles;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;
@@ -26,10 +27,12 @@
import org.oransc.rappmanager.exception.ServiceException;
import org.oransc.rappmanager.service.App;
import org.oransc.rappmanager.service.AppStore;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
// Supports only helm3 + version
public class HelmClient {
-
+ private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
private final AppStore appStore;
public HelmClient(AppStore appStore) {
@@ -63,12 +66,14 @@
Process process = builder.start();
process.waitFor();
int exitValue = process.exitValue();
- String output = IOUtils.toString(process.getInputStream(), StandardCharsets.UTF_8);
if (exitValue != 0) {
String error = IOUtils.toString(process.getErrorStream(), StandardCharsets.UTF_8);
+ logger.error("Executing helm command {} failed, exitValue: {} {}", toString(builder), exitValue, error);
throw new ServiceException("Command execution failed: " + builder + " " + error);
}
+ String output = IOUtils.toString(process.getInputStream(), StandardCharsets.UTF_8);
+ logger.debug("Command execution, output:{}", output);
return output;
} catch (Exception e) {
throw new ServiceException("Failed to execute the Command", e);
@@ -77,21 +82,20 @@
public ProcessBuilder prepareInstallCommand(App app) {
- List<String> helmArguments = Arrays.asList("helm", //
- "install", releaseName(app), getChartFileName(app), //
- "--version", app.getVersion(), //
- "--namespace", app.getNamespace());
- addKubeApiInfo(helmArguments);
+ List<String> helmArguments = Arrays.asList(//
+ "helm", //
+ "install", getChartFileName(app), //
+ "--name", releaseName(app), //
+ "--namespace", app.getNamespace(), //
+ "--values", getOverrideFileName(app));
+
+ // addKubeApiInfo(helmArguments);
ProcessBuilder processBuilder = new ProcessBuilder();
return processBuilder.command(helmArguments);
}
public ProcessBuilder prepareUnInstallCommand(App app) {
- List<String> helmArguments = Arrays.asList("helm", "uninstall", releaseName(app), //
- "--namespace", app.getNamespace());
- addKubeApiInfo(helmArguments);
- ProcessBuilder processBuilder = new ProcessBuilder();
- return processBuilder.command(helmArguments);
+ return new ProcessBuilder("helm", "delete", releaseName(app), "--purge");
}
private void addKubeApiInfo(List<String> helmArguments) {
@@ -103,4 +107,11 @@
helmArguments.addAll(kubeApiInfo);
}
+ protected static String toString(ProcessBuilder builder) {
+ StringBuilder str = new StringBuilder();
+ builder.command().forEach(arg -> str.append(" " + arg));
+ return str.toString().trim();
+
+ }
+
}
diff --git a/rapp-manager/src/test/java/org/oransc/rappmanager/controller/KubernetesTest.java b/rapp-manager/src/test/java/org/oransc/rappmanager/controller/KubernetesTest.java
index 36c07e7..547c4d3 100644
--- a/rapp-manager/src/test/java/org/oransc/rappmanager/controller/KubernetesTest.java
+++ b/rapp-manager/src/test/java/org/oransc/rappmanager/controller/KubernetesTest.java
@@ -59,7 +59,7 @@
"app.vardata-directory=./target" //
})
public class KubernetesTest {
- private final static Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+ private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
private static Gson gson = new GsonBuilder().serializeNulls().create();
private final static String APP_NAME = "test-application";
private final static String VERSION = "1.0.0";
@@ -81,17 +81,13 @@
@Override
public ProcessBuilder prepareInstallCommand(App app) {
- String installCommand = "helm install " + getChartFileName(app) + //
- " --name " + releaseName(app) + //
- " --namespace " + app.getNamespace() + //
- " --values " + getOverrideFileName(app);
-
+ String installCommand = toString(super.prepareInstallCommand(app));
return executeInVagrant(installCommand);
}
@Override
public ProcessBuilder prepareUnInstallCommand(App app) {
- String unistall = "helm delete " + releaseName(app) + " --purge";
+ String unistall = toString(super.prepareUnInstallCommand(app));
return executeInVagrant(unistall);
}
diff --git a/rapp-manager/src/test/resources/Vagrantfile b/rapp-manager/src/test/resources/Vagrantfile
new file mode 100644
index 0000000..4929946
--- /dev/null
+++ b/rapp-manager/src/test/resources/Vagrantfile
@@ -0,0 +1,8 @@
+Vagrant.configure("2") do |config|
+ config.vm.box = "generic/ubuntu1804"
+ config.vm.provision "file", source: "install.sh", destination: "install.sh"
+ config.vm.network "forwarded_port", guest_ip: "127.0.0.1", guest: 8001, host: 9080
+ config.vm.synced_folder "/home/qpatbuh/", "/home/vagrant/host_filesystem"
+ config.vm.synced_folder "/home/qpatbuh/src/nonrtric-prototyping/rapp-manager/target", "/home/vagrant/target"
+
+end
diff --git a/rapp-manager/src/test/resources/install.sh b/rapp-manager/src/test/resources/install.sh
new file mode 100755
index 0000000..f8bb71e
--- /dev/null
+++ b/rapp-manager/src/test/resources/install.sh
@@ -0,0 +1,131 @@
+#!/bin/bash
+
+# Script to run as root in a maiden Ubuntu VM in Vagrant. Will bring up Non-RT RIC in MiniKube, start the dashboard and proxy.
+# NOTE: Do 'sudo su' before running the script
+
+#Log all cmds to stdout
+set -x
+
+#Fetch and install docker
+curl -fsSL https://get.docker.com -o get-docker.sh
+
+sh get-docker.sh
+
+#Install conntrack
+apt-get install conntrack
+
+#Install socat
+apt install socat
+
+#Fetch and install minikube
+curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 \
+ && chmod +x minikube
+
+mkdir -p /usr/local/bin/
+
+install minikube /usr/local/bin/
+
+#Start minikube
+minikube start --vm-driver=none
+
+#Fetch and install kubectl
+
+curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl
+
+chmod +x ./kubectl
+
+mv ./kubectl /usr/local/bin/kubectl
+
+kubectl version --client #Just print the version
+
+#Fetch helm
+curl -L https://git.io/get_helm.sh | bash
+
+#Create the service account
+cat > tiller-serviceaccount.yaml << EOF
+apiVersion: v1
+kind: ServiceAccount
+metadata:
+ name: tiller
+ namespace: kube-system
+---
+kind: ClusterRoleBinding
+apiVersion: rbac.authorization.k8s.io/v1beta1
+metadata:
+ name: tiller-clusterrolebinding
+subjects:
+- kind: ServiceAccount
+ name: tiller
+ namespace: kube-system
+roleRef:
+ kind: ClusterRole
+ name: cluster-admin
+ apiGroup: ""
+EOF
+
+kubectl create -f tiller-serviceaccount.yaml
+
+#Fetch and deploy the metrics server
+kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/download/v0.3.7/components.yaml
+kubectl get deployment metrics-server -n kube-system
+
+#Fetch and deploy the kubernetes dashboard
+kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.2/aio/deploy/recommended.yaml
+kubectl delete clusterrolebinding kubernetes-dashboard
+kubectl create clusterrolebinding kubernetes-dashboard --clusterrole=cluster-admin --serviceaccount=kube-system:kubernetes-dashboard --user=clusterUser
+
+#Run helm
+helm init --service-account tiller --upgrade
+
+
+#Clone dep repo and deploy nonrtric components
+#git clone "https://gerrit.o-ran-sc.org/r/it/dep"
+
+#cd dep/bin
+
+#./deploy-nonrtric -f ../nonrtric/RECIPE_EXAMPLE/example_recipe.yaml
+
+#cd ../..
+
+#Create an account for login to the dashboard
+cat > eks-admin-service-account.yaml << EOF
+apiVersion: v1
+kind: ServiceAccount
+metadata:
+ name: eks-admin
+ namespace: kube-system
+---
+apiVersion: rbac.authorization.k8s.io/v1beta1
+kind: ClusterRoleBinding
+metadata:
+ name: eks-admin
+roleRef:
+ apiGroup: rbac.authorization.k8s.io
+ kind: ClusterRole
+ name: cluster-admin
+subjects:
+- kind: ServiceAccount
+ name: eks-admin
+ namespace: kube-system
+EOF
+
+#Apply the account
+kubectl apply -f eks-admin-service-account.yaml
+
+#Print the 'secret' token. Needed for login from the browser on the host
+kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep eks-admin | awk '{print $1}')
+
+#Create serviceaccount and clusterrolebinding and patch the tiller-deployment to user service account.
+kubectl create serviceaccount --namespace kube-system tiller
+kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller
+kubectl patch deploy --namespace kube-system tiller-deploy -p '{"spec":{"template":{"spec":{"serviceAccount":"tiller"}}}}'
+cp -r /root/.kube /home/vagrant
+chown vagrant /home/vagrant/.kube
+chown vagrant /home/vagrant/.kube/config
+
+
+
+
+#Start the proxy so the dashboard can be accessed from the host machine
+kubectl proxy
+