From 6290fbed75c947d03985a49e73dacea7fe8b223e Mon Sep 17 00:00:00 2001
From: still <lynn.still@polarisalpha.com>
Date: Fri, 26 Feb 2021 11:31:32 -0700
Subject: [PATCH] feat: split minio into minio operator and minio and move to
 addons

---
 .../minio/minio-operator/gitrepository.yaml   |  6 +-
 .../minio-operator-helmrelease.yaml           |  4 +-
 .../minio/minio-operator/namespace.yaml       |  6 +-
 .../gitrepository.yaml                        |  6 +-
 .../minio-helmrelease.yaml}                   | 11 +++-
 .../{minio-instance => minio}/namespace.yaml  |  5 +-
 chart/templates/values.yaml                   |  4 +-
 chart/values.yaml                             | 55 +++++++++++--------
 8 files changed, 59 insertions(+), 38 deletions(-)
 rename chart/templates/minio/{minio-instance => minio}/gitrepository.yaml (59%)
 rename chart/templates/minio/{minio-instance/minio-instance-helmrelease.yaml => minio/minio-helmrelease.yaml} (74%)
 rename chart/templates/minio/{minio-instance => minio}/namespace.yaml (78%)

diff --git a/chart/templates/minio/minio-operator/gitrepository.yaml b/chart/templates/minio/minio-operator/gitrepository.yaml
index 434a43c8b9..6d80c63d41 100644
--- a/chart/templates/minio/minio-operator/gitrepository.yaml
+++ b/chart/templates/minio/minio-operator/gitrepository.yaml
@@ -1,4 +1,4 @@
-{{- if and (not .Values.offline) .Values.minio.enabled }}
+{{- if and (not .Values.offline) .Values.addons.minioOperator.enabled }}
 apiVersion: source.toolkit.fluxcd.io/v1beta1
 kind: GitRepository
 metadata:
@@ -6,9 +6,9 @@ metadata:
   namespace: {{ .Release.Namespace }}
 spec:
   interval: {{ .Values.flux.interval }}
-  url: {{ .Values.minio.miniooperator.git.repo }}
+  url: {{ .Values.addons.minioOperator.git.repo }}
   ref:
-    {{- include "validRef" .Values.minio.miniooperator.git | nindent 4 }}
+    {{- include "validRef" .Values.addons.minioOperator.git | nindent 4 }}
   {{ include "gitIgnore" . }}
   {{- include "gitCreds" . | nindent 2 }}
 {{- end }}
diff --git a/chart/templates/minio/minio-operator/minio-operator-helmrelease.yaml b/chart/templates/minio/minio-operator/minio-operator-helmrelease.yaml
index e465cc3a15..31a6d81947 100644
--- a/chart/templates/minio/minio-operator/minio-operator-helmrelease.yaml
+++ b/chart/templates/minio/minio-operator/minio-operator-helmrelease.yaml
@@ -1,4 +1,4 @@
-{{- if .Values.minio.enabled }}
+{{- if .Values.addons.minioOperator.enabled }}
 apiVersion: helm.toolkit.fluxcd.io/v2beta1
 kind: HelmRelease
 metadata:
@@ -8,7 +8,7 @@ spec:
   targetNamespace: minio-operator
   chart:
     spec:
-      chart: {{ .Values.minio.miniooperator.git.path }}
+      chart: {{ .Values.addons.minioOperator.git.path }}
       interval: 5m
       sourceRef:
         kind: GitRepository
diff --git a/chart/templates/minio/minio-operator/namespace.yaml b/chart/templates/minio/minio-operator/namespace.yaml
index 6dfcf44dc7..88a1e7cdfe 100644
--- a/chart/templates/minio/minio-operator/namespace.yaml
+++ b/chart/templates/minio/minio-operator/namespace.yaml
@@ -1,10 +1,14 @@
-{{- if .Values.minio.enabled }}
+{{- if .Values.addons.minioOperator.enabled }}
 apiVersion: v1
 kind: Namespace
 metadata:
   name: minio-operator
   labels:
     istio-injection: enabled
+    app.kubernetes.io/name: minioOperator
+    app.kubernetes.io/component: "application-utilities"
+    {{- include "commonLabels" . | nindent 4}}
+
 ---
 {{- if ( include "imagePullSecret" . ) }}
 apiVersion: v1
diff --git a/chart/templates/minio/minio-instance/gitrepository.yaml b/chart/templates/minio/minio/gitrepository.yaml
similarity index 59%
rename from chart/templates/minio/minio-instance/gitrepository.yaml
rename to chart/templates/minio/minio/gitrepository.yaml
index cd9a1380f0..8f60b19330 100644
--- a/chart/templates/minio/minio-instance/gitrepository.yaml
+++ b/chart/templates/minio/minio/gitrepository.yaml
@@ -1,4 +1,4 @@
-{{- if and (not .Values.offline) .Values.minio.enabled }}
+{{- if and (not .Values.offline) .Values.addons.minio.enabled }}
 apiVersion: source.toolkit.fluxcd.io/v1beta1
 kind: GitRepository
 metadata:
@@ -6,9 +6,9 @@ metadata:
   namespace: {{ .Release.Namespace }}
 spec:
   interval: {{ .Values.flux.interval }}
-  url: {{ .Values.minio.minioinstance.git.repo }}
+  url: {{ .Values.addons.minio.git.repo }}
   ref:
-    {{- include "validRef" .Values.minio.minioinstance.git | nindent 4 }}
+    {{- include "validRef" .Values.addons.minio.git | nindent 4 }}
   {{ include "gitIgnore" . }}
   {{- include "gitCreds" . | nindent 2 }}
 {{- end }}
diff --git a/chart/templates/minio/minio-instance/minio-instance-helmrelease.yaml b/chart/templates/minio/minio/minio-helmrelease.yaml
similarity index 74%
rename from chart/templates/minio/minio-instance/minio-instance-helmrelease.yaml
rename to chart/templates/minio/minio/minio-helmrelease.yaml
index d4bdeb2eb2..588437c54b 100644
--- a/chart/templates/minio/minio-instance/minio-instance-helmrelease.yaml
+++ b/chart/templates/minio/minio/minio-helmrelease.yaml
@@ -1,4 +1,4 @@
-{{- if .Values.minio.enabled }}
+{{- if .Values.addons.minio.enabled }}
 apiVersion: helm.toolkit.fluxcd.io/v2beta1
 kind: HelmRelease
 metadata:
@@ -8,7 +8,7 @@ spec:
   targetNamespace: minio
   chart:
     spec:
-      chart: {{ .Values.minio.minioinstance.git.path }}
+      chart: {{ .Values.addons.minio.git.path }}
       interval: 5m
       sourceRef:
         kind: GitRepository
@@ -44,6 +44,13 @@ spec:
       traffic.sidecar.istio.io/excludeInboundPorts: "9443"
     imagePullSecrets:
       - name: private-registry
+    hostname: {{ .Values.hostname }}
+    istio:
+      enabled: {{ .Values.istio.enabled }}
+      virtualService:
+        enabled: {{ .Values.addons.minio.virtualService.enabled }}
+        name: {{ .Values.addons.minio.virtualService.name }}
+    nameOverride: {{ .Values.addons.minio.name }}
 
   dependsOn:
     - name: minio-operator
diff --git a/chart/templates/minio/minio-instance/namespace.yaml b/chart/templates/minio/minio/namespace.yaml
similarity index 78%
rename from chart/templates/minio/minio-instance/namespace.yaml
rename to chart/templates/minio/minio/namespace.yaml
index aeb4bb77bb..22a8cb953f 100644
--- a/chart/templates/minio/minio-instance/namespace.yaml
+++ b/chart/templates/minio/minio/namespace.yaml
@@ -1,10 +1,13 @@
-{{- if .Values.minio.enabled }}
+{{- if .Values.addons.minio.enabled }}
 apiVersion: v1
 kind: Namespace
 metadata:
   name: minio
   labels:
     istio-injection: enabled
+    app.kubernetes.io/name: minio
+    app.kubernetes.io/component: "application-utilities"
+    {{- include "commonLabels" . | nindent 4}}
 ---
 {{- if (   include "imagePullSecret" . ) }}
 apiVersion: v1
diff --git a/chart/templates/values.yaml b/chart/templates/values.yaml
index 9a897291f1..f8eb0a6641 100644
--- a/chart/templates/values.yaml
+++ b/chart/templates/values.yaml
@@ -50,9 +50,9 @@ stringData:
   clusterauditor.yaml: |
 {{ toYaml .Values.twistlock.values | indent 4 }}
   miniooperator.yaml: |
-{{ toYaml .Values.minio.miniooperator.values | indent 4 }}
+{{ toYaml .Values.addons.minioOperator.values | indent 4 }}
   minio.yaml: |
-{{ toYaml .Values.minio.minioinstance.values | indent 4 }}
+{{ toYaml .Values.addons.minio.values | indent 4 }}
   gitlab.yaml: |
 {{ toYaml .Values.addons.gitlab.values | indent 4 }}
   anchore.yaml: |
diff --git a/chart/values.yaml b/chart/values.yaml
index 4ef9a91f7f..1df80b9840 100644
--- a/chart/values.yaml
+++ b/chart/values.yaml
@@ -266,30 +266,6 @@ twistlock:
   # -- Values to passthrough to the twistlock chart: https://repo1.dso.mil/platform-one/big-bang/apps/security-tools/twistlock.git
   values: {}
 
-# ----------------------------------------------------------------------------------------------------------------------
-# Minio Operator and Instance
-#
-minio:
-  # -- Toggle deployment of minio operator and instance.
-  enabled: true
-  miniooperator:
-    git:
-      repo: https://repo1.dso.mil/platform-one/big-bang/apps/application-utilities/minio-operator.git
-      path: "./chart"
-      tag: "2.0.9-bb.1"
-
-    # -- Values to passthrough to the minio operator chart: https://repo1.dso.mil/platform-one/big-bang/apps/application-utilities/minio-operator.git
-    values: {}
-
-  minioinstance:
-    git:
-      repo: https://repo1.dso.mil/platform-one/big-bang/apps/application-utilities/minio.git
-      path: "./chart"
-      tag: "2.0.9-bb.1"
-
-    # -- Values to passthrough to the minio instance chart: https://repo1.dso.mil/platform-one/big-bang/apps/application-utilities/minio.git
-    values: {}
-
 #
 # ----------------------------------------------------------------------------------------------------------------------
 #
@@ -341,6 +317,37 @@ addons:
     # -- Additional authservice chain configurations.
     chains: {}
 
+  # ----------------------------------------------------------------------------------------------------------------------
+  # Minio Operator and Instance
+  #
+  minioOperator:
+    # -- Toggle deployment of minio operator and instance.
+    enabled: false
+    git:
+      repo: https://repo1.dso.mil/platform-one/big-bang/apps/application-utilities/minio-operator.git
+      path: "./chart"
+      tag: "2.0.9-bb.2"
+    # -- Values to passthrough to the minio operator chart: https://repo1.dso.mil/platform-one/big-bang/apps/application-utilities/minio-operator.git
+    values: {}
+
+  minio:
+    enabled: false
+    git:
+      repo: https://repo1.dso.mil/platform-one/big-bang/apps/application-utilities/minio.git
+      path: "./chart"
+      tag: "2.0.9-bb.2"
+
+    # Provide a specific name for the minio instance.
+    name: minio
+
+    # Settings to enable/disable and name the minio virtual service for external access to the minio UI.
+    virtualService:
+      enabled: true
+      name: minio
+
+    # -- Values to passthrough to the minio instance chart: https://repo1.dso.mil/platform-one/big-bang/apps/application-utilities/minio.git
+    values: {}
+
   gitlab:
     # -- Toggle deployment of Gitlab.
     enabled: false
-- 
GitLab