Helm manager app 17/6317/2
authorBjornMagnussonXA <bjorn.magnusson@est.tech>
Tue, 1 Jun 2021 23:56:26 +0000 (01:56 +0200)
committerBjornMagnussonXA <bjorn.magnusson@est.tech>
Tue, 15 Jun 2021 09:08:01 +0000 (11:08 +0200)
Docker scripts
Kubernetes script
Image build scripts
Config files
Test files

Issue-ID: NONRTRIC-529
Signed-off-by: BjornMagnussonXA <bjorn.magnusson@est.tech>
Change-Id: I25deb86bc815c5d63c5ff7c0dcb7a157ddee734e

15 files changed:
helm-manager/.gitignore [new file with mode: 0644]
helm-manager/Dockerfile [new file with mode: 0644]
helm-manager/config/KubernetesParticipantConfig.json [new file with mode: 0644]
helm-manager/config/application.yaml [new file with mode: 0644]
helm-manager/docker-cm.sh [new file with mode: 0755]
helm-manager/docker-hm.sh [new file with mode: 0755]
helm-manager/helm-manager-sa.yaml [new file with mode: 0644]
helm-manager/helm-manager.yaml [new file with mode: 0644]
helm-manager/kube-cm.yaml [new file with mode: 0644]
helm-manager/mnt/database/.gitignore [new file with mode: 0644]
helm-manager/pom.xml [new file with mode: 0644]
helm-manager/simple-app-installation.json [new file with mode: 0644]
helm-manager/simple-app-values.yaml [new file with mode: 0644]
helm-manager/simple-app.json [new file with mode: 0644]
helm-manager/test.sh [new file with mode: 0755]

diff --git a/helm-manager/.gitignore b/helm-manager/.gitignore
new file mode 100644 (file)
index 0000000..5e41250
--- /dev/null
@@ -0,0 +1,4 @@
+charts
+simple-app
+target
+*.tgz
diff --git a/helm-manager/Dockerfile b/helm-manager/Dockerfile
new file mode 100644 (file)
index 0000000..b9283c0
--- /dev/null
@@ -0,0 +1,47 @@
+#  ============LICENSE_START===============================================
+#  Copyright (C) 2020 Nordix Foundation. All rights reserved.
+#  ========================================================================
+#  Licensed under the Apache License, Version 2.0 (the "License");
+#  you may not use this file except in compliance with the License.
+#  You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+#  ============LICENSE_END=================================================
+#
+
+FROM openjdk:11-jre-slim
+
+ARG JAR
+
+#Install curl
+RUN apt-get update
+RUN apt-get install -y curl
+
+#Install helm
+RUN curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
+RUN chmod 700 get_helm.sh
+RUN ./get_helm.sh
+
+#Install kubectl and configure
+RUN curl -LO https://dl.k8s.io/release/v1.20.2/bin/linux/amd64/kubectl
+
+RUN chmod +x ./kubectl
+
+RUN mv ./kubectl /usr/local/bin/kubectl
+
+# Copy app config and app jar
+WORKDIR /opt/app/helm-manager/src/main/resources/config
+
+COPY config/KubernetesParticipantConfig.json .
+COPY config/application.yaml .
+
+WORKDIR /opt/app/helm-manager
+COPY target/app.jar app.jar
+
+CMD [ "java", "-jar", "app.jar" ]
diff --git a/helm-manager/config/KubernetesParticipantConfig.json b/helm-manager/config/KubernetesParticipantConfig.json
new file mode 100644 (file)
index 0000000..7eeb456
--- /dev/null
@@ -0,0 +1,49 @@
+{
+    "name": "ControlLoopParticipantK8s",
+    "localChartDirectory": "/var/helm-manager/local-charts",
+    "infoFileName": "CHART_INFO.json",
+
+    "intermediaryParameters":{
+        "name":"Participant parameters",
+        "reportingTimeInterval":120000,
+        "description":"Participant Description",
+        "participantId":{
+            "name":"K8sParticipant0",
+            "version":"1.0.0"
+        },
+        "participantType":{
+            "name":"org.onap.k8s.controlloop.K8SControlLoopParticipant",
+            "version":"2.3.4"
+        },
+        "clampControlLoopTopics":{
+            "topicSources":[
+
+            ],
+            "topicSinks":[
+                {
+                    "topic":"POLICY-CLRUNTIME-PARTICIPANT",
+                    "servers":[
+                        "localhost"
+                    ],
+                    "topicCommInfrastructure":"dmaap"
+                },
+                {
+                    "topic":"POLICY-NOTIFICATION",
+                    "servers":[
+                        "localhost"
+                    ],
+                    "topicCommInfrastructure":"dmaap"
+                }
+            ]
+        }
+    },
+    "databaseProviderParameters":{
+        "name":"PolicyProviderParameterGroup",
+        "implementation":"org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl",
+        "databaseDriver":"org.mariadb.jdbc.Driver",
+        "databaseUrl":"jdbc:mariadb://localhost:3306/controlloop",
+        "databaseUser":"admin",
+        "databasePassword":"passme",
+        "persistenceUnit":"ToscaConceptTest"
+    }
+}
diff --git a/helm-manager/config/application.yaml b/helm-manager/config/application.yaml
new file mode 100644 (file)
index 0000000..44de509
--- /dev/null
@@ -0,0 +1,42 @@
+#  ============LICENSE_START===============================================
+#  Copyright (C) 2020 Nordix Foundation. All rights reserved.
+#  ========================================================================
+#  Licensed under the Apache License, Version 2.0 (the "License");
+#  you may not use this file except in compliance with the License.
+#  You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+#  ============LICENSE_END=================================================
+#
+
+spring:
+  profiles:
+    active: prod
+
+participant:
+  file: src/main/resources/config/KubernetesParticipantConfig.json
+management:
+  endpoints:
+    web:
+      exposure:
+        include: "loggers,logfile,health,info,metrics,threaddump,heapdump"
+server:
+  # Configuration of the HTTP/REST server. The parameters are defined and handled by the springboot framework.
+  # See springboot documentation.
+  http-port : 8083
+
+logging:
+  # Configuration of logging
+  level:
+    ROOT: INFO
+    org.springframework: ERROR
+    org.springframework.data: ERROR
+    org.springframework.web.reactive.function.client.ExchangeFunctions: ERROR
+  file:
+    name: /var/log/helm-manager/application.log
diff --git a/helm-manager/docker-cm.sh b/helm-manager/docker-cm.sh
new file mode 100755 (executable)
index 0000000..bf55bef
--- /dev/null
@@ -0,0 +1,30 @@
+#! /bin/bash
+
+#  ============LICENSE_START===============================================
+#  Copyright (C) 2021 Nordix Foundation. All rights reserved.
+#  ========================================================================
+#  Licensed under the Apache License, Version 2.0 (the "License");
+#  you may not use this file except in compliance with the License.
+#  You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+#  ============LICENSE_END=================================================
+
+# Starts a chartmuseum container
+
+
+docker run --rm -it \
+    -p 8222:8080 \
+    --name chartmuseum \
+    --network nonrtric-docker-net \
+    -e DEBUG=1 \
+    -e STORAGE=local \
+    -e STORAGE_LOCAL_ROOTDIR=/charts \
+    -v $(pwd)/charts:/charts \
+    ghcr.io/helm/chartmuseum:v0.13.1
\ No newline at end of file
diff --git a/helm-manager/docker-hm.sh b/helm-manager/docker-hm.sh
new file mode 100755 (executable)
index 0000000..c98b22a
--- /dev/null
@@ -0,0 +1,34 @@
+#! /bin/bash
+
+#  ============LICENSE_START===============================================
+#  Copyright (C) 2021 Nordix Foundation. All rights reserved.
+#  ========================================================================
+#  Licensed under the Apache License, Version 2.0 (the "License");
+#  you may not use this file except in compliance with the License.
+#  You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+#  ============LICENSE_END=================================================
+
+# Starts a helm manager container
+
+docker run \
+    --rm  \
+    -it \
+    -p 8112:8083  \
+    --name helmmanagerservice \
+    --network nonrtric-docker-net \
+    -v $(pwd)/mnt/database:/var/helm-manager/database \
+    -v ~/.kube:/root/.kube \
+    -v ~/.helm:/root/.helm \
+    -v ~/.config/helm:/root/.config/helm \
+    -v ~/.cache/helm:/root/.cache/helm \
+    -v $(pwd)/config/KubernetesParticipantConfig.json:/opt/app/helm-manager/src/main/resources/config/KubernetesParticipantConfig.json \
+    -v $(pwd)/config/application.yaml:/opt/app/helm-manager/src/main/resources/config/application.yaml \
+    nexus3.o-ran-sc.org:10004/o-ran-sc/nonrtric-helm-manager:1.0.0-SNAPSHOT
\ No newline at end of file
diff --git a/helm-manager/helm-manager-sa.yaml b/helm-manager/helm-manager-sa.yaml
new file mode 100644 (file)
index 0000000..3ac50e5
--- /dev/null
@@ -0,0 +1,36 @@
+#  ============LICENSE_START===============================================
+#  Copyright (C) 2020 Nordix Foundation. All rights reserved.
+#  ========================================================================
+#  Licensed under the Apache License, Version 2.0 (the "License");
+#  you may not use this file except in compliance with the License.
+#  You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+#  ============LICENSE_END=================================================
+#
+
+apiVersion: v1
+kind: ServiceAccount
+metadata:
+ name: helm-manager-sa
+ namespace: nonrtric
+---
+apiVersion: rbac.authorization.k8s.io/v1
+kind: ClusterRoleBinding
+metadata:
+ name: helm-manager-sa-clusterrolebinding
+ namespace: nonrtric
+subjects:
+- kind: ServiceAccount
+  name: helm-manager-sa
+  namespace: nonrtric
+roleRef:
+ kind: ClusterRole
+ name: cluster-admin
+ apiGroup: rbac.authorization.k8s.io
\ No newline at end of file
diff --git a/helm-manager/helm-manager.yaml b/helm-manager/helm-manager.yaml
new file mode 100644 (file)
index 0000000..093752e
--- /dev/null
@@ -0,0 +1,101 @@
+#  ============LICENSE_START===============================================
+#  Copyright (C) 2020 Nordix Foundation. All rights reserved.
+#  ========================================================================
+#  Licensed under the Apache License, Version 2.0 (the "License");
+#  you may not use this file except in compliance with the License.
+#  You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+#  ============LICENSE_END=================================================
+#
+
+apiVersion: v1
+kind: Service
+metadata:
+  name: helmmanagerservice
+  namespace: nonrtric
+  labels:
+    run: helmmanagerservice
+spec:
+  type: NodePort
+  ports:
+  - port: 8080
+    targetPort: 8080
+    protocol: TCP
+    name: http
+  - port: 8443
+    targetPort: 8443
+    protocol: TCP
+    name: https
+  selector:
+    run: helmmanagerservice
+
+---
+
+apiVersion: v1
+kind: Pod
+metadata:
+  name: helmmanagerservice
+  namespace: nonrtric
+  labels:
+    run: helmmanagerservice
+spec:
+  serviceAccountName: helm-manager-sa
+  containers:
+  - name: helmmanagerservice
+    image: nexus3.o-ran-sc.org:10004/o-ran-sc/nonrtric-helm-manager:1.0.0-SNAPSHOT
+    imagePullPolicy: Always
+    ports:
+    - name: http
+      containerPort: 8080
+    - name: https
+      containerPort: 8443
+    volumeMounts:
+    - mountPath: /var/helm-manager-service
+      name: helm-manager-service-pv
+  volumes:
+  - name: helm-manager-service-pv
+    persistentVolumeClaim:
+      claimName: helm-manager-service-pvc
+
+---
+
+apiVersion: v1
+kind: PersistentVolume
+metadata:
+  name: helm-manager-service-pv
+  labels:
+    run: helm-manager-service
+spec:
+  storageClassName: helm-manager-service-standard
+  capacity:
+    storage: 10Mi
+  accessModes:
+    - ReadWriteOnce
+  persistentVolumeReclaimPolicy: Delete
+  hostPath:
+    path: "/tmp/helm-manager-service"
+
+---
+
+apiVersion: v1
+kind: PersistentVolumeClaim
+metadata:
+  name: helm-manager-service-pvc
+  namespace: nonrtric
+  labels:
+    run: helm-manager-service
+spec:
+  accessModes:
+  - ReadWriteOnce
+  resources:
+    requests:
+      storage: 10Mi
+  storageClassName: helm-manager-service-standard
+  volumeMode: Filesystem
diff --git a/helm-manager/kube-cm.yaml b/helm-manager/kube-cm.yaml
new file mode 100644 (file)
index 0000000..c75ebd5
--- /dev/null
@@ -0,0 +1,108 @@
+#  ============LICENSE_START===============================================
+#  Copyright (C) 2020 Nordix Foundation. All rights reserved.
+#  ========================================================================
+#  Licensed under the Apache License, Version 2.0 (the "License");
+#  you may not use this file except in compliance with the License.
+#  You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+#  ============LICENSE_END=================================================
+#
+
+apiVersion: v1
+kind: Service
+metadata:
+  name: chartrepo
+  namespace: nonrtric
+  labels:
+    run: chartrepo
+spec:
+  type: NodePort
+  ports:
+  - port: 8080
+    targetPort: 8080
+    protocol: TCP
+    name: http
+  selector:
+    run: chartrepo
+
+---
+
+apiVersion: v1
+kind: Pod
+metadata:
+  name: chartrepo
+  namespace: nonrtric
+  labels:
+    run: chartrepo
+spec:
+  securityContext:
+    runAsUser: 0
+  containers:
+  - name: chartrepo
+    image: ghcr.io/helm/chartmuseum:v0.13.1
+    imagePullPolicy: Always
+    ports:
+    - name: http
+      containerPort: 8080
+    env:
+    - name: DEBUG
+      value: "1"
+    - name: STORAGE
+      value: "local"
+    - name: STORAGE_LOCAL_ROOTDIR
+      value: "/var/chartrepo/charts"
+    - name: DISABLE_API
+      value: "false"
+    volumeMounts:
+    - mountPath: /var/chartrepo/charts
+      name: chartrepo-pv
+  volumes:
+  - name: chartrepo-pv
+    persistentVolumeClaim:
+      claimName: chartrepo-pvc
+
+
+---
+
+apiVersion: v1
+kind: PersistentVolume
+metadata:
+  name: chartrepo-pv
+  annotations:
+    pv.beta.kubernetes.io/gid: "999"
+  labels:
+    run: chartrepo
+spec:
+  storageClassName: chartrepo-standard
+  capacity:
+    storage: 10Mi
+  accessModes:
+    - ReadWriteOnce
+  persistentVolumeReclaimPolicy: Delete
+  hostPath:
+    path: "/tmp/chartrepo"
+
+---
+
+apiVersion: v1
+kind: PersistentVolumeClaim
+metadata:
+  name: chartrepo-pvc
+  namespace: nonrtric
+  labels:
+    run: chartrepo
+spec:
+  accessModes:
+  - ReadWriteOnce
+  resources:
+    requests:
+      storage: 10Mi
+  storageClassName: chartrepo-standard
+  volumeMode: Filesystem
diff --git a/helm-manager/mnt/database/.gitignore b/helm-manager/mnt/database/.gitignore
new file mode 100644 (file)
index 0000000..72e8ffc
--- /dev/null
@@ -0,0 +1 @@
+*
diff --git a/helm-manager/pom.xml b/helm-manager/pom.xml
new file mode 100644 (file)
index 0000000..0c52a12
--- /dev/null
@@ -0,0 +1,146 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+* ========================LICENSE_START=================================
+* O-RAN-SC
+* %%
+* Copyright (C) 2021 Nordix Foundation
+* %%
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+* ========================LICENSE_END===================================
+-->
+<project
+    xmlns="http://maven.apache.org/POM/4.0.0"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.springframework.boot</groupId>
+        <artifactId>spring-boot-starter-parent</artifactId>
+        <version>2.3.8.RELEASE</version>
+        <relativePath />
+    </parent>
+    <groupId>org.o-ran-sc.nonrtric</groupId>
+    <artifactId>helm-manager</artifactId>
+    <!-- Update this when stepping version of the helm-manager -->
+    <version>1.0.0-SNAPSHOT</version>
+    <licenses>
+        <license>
+            <name>The Apache Software License, Version 2.0</name>
+            <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
+        </license>
+    </licenses>
+    <properties>
+        <!-- Update this when a new version of the dependency jar shall be included -->
+        <policy-clamp-participant-impl-kubernetes.version>6.1.2-SNAPSHOT</policy-clamp-participant-impl-kubernetes.version>
+        <docker-maven-plugin.version>0.36.0</docker-maven-plugin.version>
+        <maven-dependency-plugin.version>3.1.2</maven-dependency-plugin.version>
+    </properties>
+    <dependencies>
+        <dependency>
+        <groupId>org.onap.policy.clamp.participant</groupId>
+        <artifactId>policy-clamp-participant-impl-kubernetes</artifactId>
+        <version>${policy-clamp-participant-impl-kubernetes.version}</version>
+        </dependency>
+    </dependencies>
+    <build>
+        <plugins>
+            <plugin>
+                <!-- Make the jar file of the dependency available as a file for inclusion in the docker image-->
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-dependency-plugin</artifactId>
+                <version>${maven-dependency-plugin.version}</version>
+                <executions>
+                <execution>
+                    <id>copy</id>
+                    <phase>package</phase>
+                    <goals>
+                    <goal>copy</goal>
+                    </goals>
+                    <configuration>
+                    <artifactItems>
+                        <artifactItem>
+                        <groupId>org.onap.policy.clamp.participant</groupId>
+                        <artifactId>policy-clamp-participant-impl-kubernetes</artifactId>
+                        <version>${policy-clamp-participant-impl-kubernetes.version}</version>
+                        <type>jar</type>
+                        <overWrite>true</overWrite>
+                        <outputDirectory>${basedir}/target</outputDirectory>
+                        <destFileName>app.jar</destFileName>
+                        </artifactItem>
+                    </artifactItems>
+                    </configuration>
+                </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>io.fabric8</groupId>
+                <artifactId>docker-maven-plugin</artifactId>
+                <version>${docker-maven-plugin.version}</version>
+                <inherited>false</inherited>
+                <executions>
+                    <execution>
+                        <id>generate-helm-manager-image</id>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>build</goal>
+                        </goals>
+                        <configuration>
+                            <pullRegistry>${env.CONTAINER_PULL_REGISTRY}</pullRegistry>
+                            <images>
+                                <image>
+                                    <name>o-ran-sc/nonrtric-helm-manager:${project.version}</name>
+                                    <build>
+                                        <cleanup>try</cleanup>
+                                        <contextDir>${basedir}</contextDir>
+                                        <dockerFile>Dockerfile</dockerFile>
+                                        <tags>
+                                            <tag>${project.version}</tag>
+                                        </tags>
+                                    </build>
+                                </image>
+                            </images>
+                        </configuration>
+                    </execution>
+                    <execution>
+                        <id>push-helm-manager-image</id>
+                        <goals>
+                            <goal>build</goal>
+                            <goal>push</goal>
+                        </goals>
+                        <configuration>
+                            <pullRegistry>${env.CONTAINER_PULL_REGISTRY}</pullRegistry>
+                            <pushRegistry>${env.CONTAINER_PUSH_REGISTRY}</pushRegistry>
+                            <images>
+                                <image>
+                                    <name>o-ran-sc/nonrtric-helm-manager:${project.version}</name>
+                                    <build>
+                                        <contextDir>${basedir}</contextDir>
+                                        <dockerFile>Dockerfile</dockerFile>
+                                        <tags>
+                                            <tag>${project.version}</tag>
+                                            <tag>latest</tag>
+                                        </tags>
+                                    </build>
+                                </image>
+                            </images>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+    <issueManagement>
+        <system>JIRA</system>
+        <url>https://jira.o-ran-sc.org/</url>
+    </issueManagement>
+</project>
\ No newline at end of file
diff --git a/helm-manager/simple-app-installation.json b/helm-manager/simple-app-installation.json
new file mode 100644 (file)
index 0000000..b9760f2
--- /dev/null
@@ -0,0 +1,4 @@
+{
+    "name": "simple-app",
+    "version": "0.1.0"
+}
\ No newline at end of file
diff --git a/helm-manager/simple-app-values.yaml b/helm-manager/simple-app-values.yaml
new file mode 100644 (file)
index 0000000..873396d
--- /dev/null
@@ -0,0 +1,23 @@
+#  ============LICENSE_START===============================================
+#  Copyright (C) 2020 Nordix Foundation. All rights reserved.
+#  ========================================================================
+#  Licensed under the Apache License, Version 2.0 (the "License");
+#  you may not use this file except in compliance with the License.
+#  You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+#  ============LICENSE_END=================================================
+#
+
+# Override values for simple-app.
+# This is a YAML-formatted file.
+# Declare variables to be passed into your templates.
+
+
+## No override values defined ##
\ No newline at end of file
diff --git a/helm-manager/simple-app.json b/helm-manager/simple-app.json
new file mode 100644 (file)
index 0000000..27f73c8
--- /dev/null
@@ -0,0 +1,7 @@
+{
+    "releaseName": "simpleapp",
+    "chartName": "simple-app",
+    "version": "0.1.0",
+    "namespace": "ckhm",
+    "repository": "cm"
+}
\ No newline at end of file
diff --git a/helm-manager/test.sh b/helm-manager/test.sh
new file mode 100755 (executable)
index 0000000..1b652bf
--- /dev/null
@@ -0,0 +1,208 @@
+#!/bin/bash
+
+#  ============LICENSE_START===============================================
+#  Copyright (C) 2021 Nordix Foundation. All rights reserved.
+#  ========================================================================
+#  Licensed under the Apache License, Version 2.0 (the "License");
+#  you may not use this file except in compliance with the License.
+#  You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+#  ============LICENSE_END=================================================
+#
+
+
+BOLD="\033[1m"
+EBOLD="\033[0m"
+BOLD="\033[1m"
+EBOLD="\033[0m"
+RED="\033[31m\033[1m"
+ERED="\033[0m"
+GREEN="\033[32m\033[1m"
+EGREEN="\033[0m"
+
+echo ""
+echo "Start test"
+
+APP_TGZ="simple-app-0.1.0.tgz"
+VALUES_YAML="simple-app-values.yaml"
+INFO_JSON="simple-app.json"
+INSTALL_JSON="simple-app-installation.json"
+
+PORT=""
+HOST=""
+URL=""
+HM_PATH=""
+NAMESPACE="ckhm"  #kube namespace for simple-app
+PROXY_TAG=""
+
+OK="All tests ok"
+
+print_usage() {
+    echo "usage: ./test.sh docker|(kube <cluster-ip>)"
+}
+if [ $# -eq 1 ]; then
+    if [ $1 == "docker" ]; then
+        PORT=8112
+        HOST="localhost"
+        URL="http://$HOST:$PORT"
+        HM_PATH=$URL
+    else
+        print_usage
+        exit 1
+    fi
+elif [ $# -eq 2 ]; then
+    if [ $1 == "kube" ]; then
+        PORT=$(kubectl get svc helmmanagerservice -n nonrtric -o jsonpath='{...ports[?(@.name=="'http'")].nodePort}')
+        HOST=$2
+        URL="http://$HOST:$PORT"
+        HM_PATH=$URL
+    else
+        print_usage
+        exit 1
+    fi
+else
+    print_usage
+    exit 1
+fi
+
+
+
+run-curl() {
+    curl_cmd="curl -sw %{http_code} $PROXY_TAG $HM_PATH$@"
+    echo $curl_cmd
+    res=$($curl_cmd)
+    retcode=$?
+    status=${res:${#res}-3}
+    if [ -z "$res" ]; then
+        body="<no-body-returned>"
+    elif [ ${#res} -gt 2 ]; then
+        body=${res:0:${#res}-3}
+    else
+        body="<no-body-returned>"
+    fi
+    if [ $retcode -ne 0 ]; then
+        echo -e $RED" FAIL -  Curl failed"$ERED
+        echo "  Curl return code: $retcode"
+        OK="One or more tests failed"
+    else
+        if [[ $status -gt 199 ]] && [[ $status -lt 300 ]]; then
+            echo -e $GREEN" Curl OK"$EGREEN
+            echo "  Response: "$status
+            echo "  Body: "$body
+        else
+            echo -e $RED" FAIL, non 2XX response"$ERED
+            echo "  Response: "$status
+            echo "  Body: "$body
+            OK="One or more tests failed"
+        fi
+    fi
+}
+
+echo "================"
+echo "Get apps - empty"
+echo "================"
+cmd="/helm/charts"
+run-curl $cmd
+echo
+
+
+echo "============"
+echo "Onboard app"
+echo "==========="
+cmd="/helm/charts -X POST -F chart=@$APP_TGZ -F values=@$VALUES_YAML -F info=<$INFO_JSON"
+run-curl $cmd
+echo
+
+
+echo "====================="
+echo "Get apps - simple-app"
+echo "====================="
+cmd="/helm/charts"
+run-curl $cmd
+echo
+
+
+echo "==========="
+echo "Install app"
+echo "==========="
+cmd="/helm/install -X POST -H Content-Type:application/json -d @$INSTALL_JSON"
+run-curl $cmd
+echo
+
+
+
+echo "====================="
+echo "Get apps - simple-app"
+echo "====================="
+cmd="/helm/charts"
+run-curl $cmd
+echo
+
+echo "================================================================="
+echo "helm ls to list installed app - simpleapp chart should be visible"
+echo "================================================================="
+helm ls -A
+echo
+
+echo "=========================================="
+echo "sleep 30 - give the app some time to start"
+echo "=========================================="
+sleep 30
+
+echo "============================"
+echo "List svc and  pod of the app"
+echo "============================"
+kubectl get svc -n $NAMESPACE
+kubectl get po -n $NAMESPACE
+echo
+
+echo "========================"
+echo "Uninstall app simple-app"
+echo "========================"
+cmd="/helm/uninstall/simple-app/0.1.0 -X DELETE"
+run-curl $cmd
+echo
+
+echo "==========================================="
+echo "sleep 30 - give the app some time to remove"
+echo "==========================================="
+sleep 30
+
+echo "============================================================"
+echo "List svc and  pod of the app - should be gone or terminating"
+echo "============================================================"
+kubectl get svc -n $NAMESPACE
+kubectl get po -n $NAMESPACE
+echo
+
+
+echo "====================="
+echo "Get apps - simple-app"
+echo "====================="
+cmd="/helm/charts"
+run-curl $cmd
+echo
+
+echo "============"
+echo "Delete chart"
+echo "==========="
+cmd="/helm/charts/simple-app/0.1.0 -X DELETE"
+run-curl $cmd
+echo
+
+echo "================"
+echo "Get apps - empty"
+echo "================"
+cmd="/helm/charts"
+run-curl $cmd
+echo
+
+echo -e "Test result $BOLD $OK $EBOLD"
+echo "End of test"