diff --git a/src/main/k8s/config-maps.yaml b/src/main/k8s/config-maps.yaml new file mode 100644 index 0000000..6cf29a7 --- /dev/null +++ b/src/main/k8s/config-maps.yaml @@ -0,0 +1,9 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: postgres-config + namespace: microservice-catalog +data: + PGDATA: /var/lib/postgresql/data/pgdata + POSTGRES_USER: microservice-catalog + POSTGRES_DB: microservice-catalog diff --git a/src/main/k8s/database-deployment.yaml b/src/main/k8s/database-deployment.yaml new file mode 100644 index 0000000..54b0138 --- /dev/null +++ b/src/main/k8s/database-deployment.yaml @@ -0,0 +1,42 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: postgres-deployment + namespace: microservice-catalog + labels: + app: microservice-catalog + tier: database +spec: + replicas: 1 + selector: + matchLabels: + app: microservice-catalog + tier: database + template: + metadata: + labels: + app: microservice-catalog + tier: database + spec: + containers: + - name: postgres + image: postgres + envFrom: + - configMapRef: + name: postgres-config + env: + - name: POSTGRES_PASSWORD + valueFrom: + secretKeyRef: + key: POSTGRES_PASSWORD + name: postgres-secret + volumeMounts: + - mountPath: /var/lib/postgresql/data + name: postgres-pv-claim + ports: + - containerPort: 5432 + protocol: TCP + volumes: + - name: postgres-pv-claim + persistentVolumeClaim: + claimName: postgres-pv-claim diff --git a/src/main/k8s/kustomization.yaml b/src/main/k8s/kustomization.yaml new file mode 100644 index 0000000..f070533 --- /dev/null +++ b/src/main/k8s/kustomization.yaml @@ -0,0 +1,11 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +resources: + - namespace.yaml + - secrets.yaml + - config-maps.yaml + - storage.yaml + - services.yaml + - database-deployment.yaml + - microservice-catalog-deployment.yaml diff --git a/src/main/k8s/microservice-catalog-deployment.yaml b/src/main/k8s/microservice-catalog-deployment.yaml new file mode 100644 index 0000000..c19e196 --- /dev/null +++ b/src/main/k8s/microservice-catalog-deployment.yaml @@ -0,0 +1,50 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: microservice-catalog + namespace: microservice-catalog + labels: + app: microservice-catalog + tier: business +spec: + replicas: 1 + selector: + matchLabels: + app: microservice-catalog + tier: business + template: + metadata: + labels: + app: microservice-catalog + tier: business + spec: + containers: + - name: microservice-catalog + image: tillias/microcatalog + env: + - name: DB_HOST + value: postgres-service + - name: DB_PORT + value: "5432" + - name: DB_NAME + valueFrom: + configMapKeyRef: + key: POSTGRES_DB + name: postgres-config + - name: DB_PASSWORD + valueFrom: + secretKeyRef: + key: POSTGRES_PASSWORD + name: postgres-secret + - name: DB_USER + valueFrom: + configMapKeyRef: + key: POSTGRES_USER + name: postgres-config + - name: CSP_IMAGE_SRC + value: "'*'" + - name: SERVER_PORT + value: "8081" + ports: + - containerPort: 8081 + protocol: TCP diff --git a/src/main/k8s/namespace.yaml b/src/main/k8s/namespace.yaml new file mode 100644 index 0000000..6f703fa --- /dev/null +++ b/src/main/k8s/namespace.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: microservice-catalog diff --git a/src/main/k8s/secrets.yaml b/src/main/k8s/secrets.yaml new file mode 100644 index 0000000..e03cb7d --- /dev/null +++ b/src/main/k8s/secrets.yaml @@ -0,0 +1,8 @@ +apiVersion: v1 +kind: Secret +metadata: + name: postgres-secret + namespace: microservice-catalog +type: Opaque +data: + POSTGRES_PASSWORD: a0V0I3VSNk0= diff --git a/src/main/k8s/services.yaml b/src/main/k8s/services.yaml new file mode 100644 index 0000000..3b93806 --- /dev/null +++ b/src/main/k8s/services.yaml @@ -0,0 +1,37 @@ +apiVersion: v1 +kind: Service +metadata: + name: postgres-service + namespace: microservice-catalog + labels: + app: microservice-catalog + tier: service +spec: + ports: + - name: postgres + port: 5432 + targetPort: 5432 + protocol: TCP + selector: + app: microservice-catalog + tier: database + +--- +apiVersion: v1 +kind: Service +metadata: + name: microservice-catalog-service + namespace: microservice-catalog + labels: + app: microservice-catalog + tier: service +spec: + ports: + - name: microservice-catalog + port: 8081 + targetPort: 8081 + protocol: TCP + type: LoadBalancer + selector: + app: microservice-catalog + tier: business diff --git a/src/main/k8s/storage.yaml b/src/main/k8s/storage.yaml new file mode 100644 index 0000000..96b9eca --- /dev/null +++ b/src/main/k8s/storage.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: postgres-pv-claim + namespace: microservice-catalog + labels: + app: microservice-catalog +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 50M diff --git a/src/test/java/com/github/microcatalog/web/rest/custom/ImpactAnalysisCustomResourceTest.java b/src/test/java/com/github/microcatalog/web/rest/custom/ImpactAnalysisCustomResourceTest.java index 928193a..0fe04a2 100644 --- a/src/test/java/com/github/microcatalog/web/rest/custom/ImpactAnalysisCustomResourceTest.java +++ b/src/test/java/com/github/microcatalog/web/rest/custom/ImpactAnalysisCustomResourceTest.java @@ -6,12 +6,9 @@ import com.github.microcatalog.utils.MicroserviceBuilder; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureWebMvc; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.MediaType; -import org.springframework.security.test.context.support.WithMockUser; import org.springframework.test.web.servlet.MockMvc; import java.util.Optional;