manifests/tests/katib-db-overlays-applicati...

233 lines
5.9 KiB
Go

package tests_test
import (
"sigs.k8s.io/kustomize/v3/k8sdeps/kunstruct"
"sigs.k8s.io/kustomize/v3/k8sdeps/transformer"
"sigs.k8s.io/kustomize/v3/pkg/fs"
"sigs.k8s.io/kustomize/v3/pkg/loader"
"sigs.k8s.io/kustomize/v3/pkg/plugins"
"sigs.k8s.io/kustomize/v3/pkg/resmap"
"sigs.k8s.io/kustomize/v3/pkg/resource"
"sigs.k8s.io/kustomize/v3/pkg/target"
"sigs.k8s.io/kustomize/v3/pkg/validators"
"testing"
)
func writeKatibDbOverlaysApplication(th *KustTestHarness) {
th.writeF("/manifests/katib-v1alpha2/katib-db/overlays/application/application.yaml", `
apiVersion: app.k8s.io/v1beta1
kind: Application
metadata:
name: katib-db
spec:
selector:
matchLabels:
app.kubernetes.io/name: katib-db
app.kubernetes.io/instance: katib-db
app.kubernetes.io/managed-by: kfctl
app.kubernetes.io/component: katib
app.kubernetes.io/part-of: kubeflow
app.kubernetes.io/version: v0.6
componentKinds:
- group: core
kind: Service
- group: apps
kind: Deployment
- group: core
kind: Secret
- group: core
kind: PersistentVolumeClaim
descriptor:
type: "katib-db"
version: "v1alpha2"
description: "Katib db provides the storage service to the katib manager."
maintainers:
- name: Zhongxuan Wu
email: wuzhongxuan@caicloud.io
- name: Ce Gao
email: gaoce@caicloud.io
- name: Johnu George
email: johnugeo@cisco.com
- name: Hougang Liu
email: liuhougang6@126.com
- name: Richard Liu
email: ricliu@google.com
- name: YujiOshima
email: yuji.oshima0x3fd@gmail.com
owners:
- name: Ce Gao
email: gaoce@caicloud.io
- name: Johnu George
email: johnugeo@cisco.com
- name: Hougang Liu
email: liuhougang6@126.com
- name: Richard Liu
email: ricliu@google.com
- name: YujiOshima
email: yuji.oshima0x3fd@gmail.com
keywords:
- katib
- katib-db
- hyperparameter tuning
links:
- description: About
url: "https://github.com/kubeflow/katib"
addOwnerRef: true
`)
th.writeK("/manifests/katib-v1alpha2/katib-db/overlays/application", `
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
bases:
- ../../base
resources:
- application.yaml
commonLabels:
app.kubernetes.io/name: katib-db
app.kubernetes.io/instance: katib-db
app.kubernetes.io/managed-by: kfctl
app.kubernetes.io/component: katib
app.kubernetes.io/part-of: kubeflow
app.kubernetes.io/version: v0.6
`)
th.writeF("/manifests/katib-v1alpha2/katib-db/base/katib-db-deployment.yaml", `
apiVersion: apps/v1
kind: Deployment
metadata:
name: katib-db
labels:
app: katib
component: db
spec:
replicas: 1
selector:
matchLabels:
app: katib
component: db
template:
metadata:
name: katib-db
labels:
app: katib
component: db
spec:
containers:
- name: katib-db
image: mysql:8.0.3
args:
- --datadir
- /var/lib/mysql/datadir
env:
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: katib-db-secrets
key: MYSQL_ROOT_PASSWORD
- name: MYSQL_ALLOW_EMPTY_PASSWORD
value: "true"
- name: MYSQL_DATABASE
value: "katib"
ports:
- name: dbapi
containerPort: 3306
readinessProbe:
exec:
command:
- "/bin/bash"
- "-c"
- "mysql -D $$MYSQL_DATABASE -p$$MYSQL_ROOT_PASSWORD -e 'SELECT 1'"
initialDelaySeconds: 5
periodSeconds: 2
timeoutSeconds: 1
volumeMounts:
- name: katib-mysql
mountPath: /var/lib/mysql
volumes:
- name: katib-mysql
persistentVolumeClaim:
claimName: katib-mysql
`)
th.writeF("/manifests/katib-v1alpha2/katib-db/base/katib-db-pvc.yaml", `
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: katib-mysql
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
`)
th.writeF("/manifests/katib-v1alpha2/katib-db/base/katib-db-secret.yaml", `
apiVersion: v1
kind: Secret
type: Opaque
metadata:
name: katib-db-secrets
data:
MYSQL_ROOT_PASSWORD: dGVzdA== # "test"
`)
th.writeF("/manifests/katib-v1alpha2/katib-db/base/katib-db-service.yaml", `
apiVersion: v1
kind: Service
metadata:
name: katib-db
labels:
app: katib
component: db
spec:
type: ClusterIP
ports:
- port: 3306
protocol: TCP
name: dbapi
selector:
app: katib
component: db
`)
th.writeK("/manifests/katib-v1alpha2/katib-db/base", `
namespace: kubeflow
resources:
- katib-db-deployment.yaml
- katib-db-pvc.yaml
- katib-db-secret.yaml
- katib-db-service.yaml
generatorOptions:
disableNameSuffixHash: true
images:
- name: mysql
newTag: 8.0.3
`)
}
func TestKatibDbOverlaysApplication(t *testing.T) {
th := NewKustTestHarness(t, "/manifests/katib-v1alpha2/katib-db/overlays/application")
writeKatibDbOverlaysApplication(th)
m, err := th.makeKustTarget().MakeCustomizedResMap()
if err != nil {
t.Fatalf("Err: %v", err)
}
expected, err := m.AsYaml()
if err != nil {
t.Fatalf("Err: %v", err)
}
targetPath := "../katib-v1alpha2/katib-db/overlays/application"
fsys := fs.MakeRealFS()
lrc := loader.RestrictionRootOnly
_loader, loaderErr := loader.NewLoader(lrc, validators.MakeFakeValidator(), targetPath, fsys)
if loaderErr != nil {
t.Fatalf("could not load kustomize loader: %v", loaderErr)
}
rf := resmap.NewFactory(resource.NewFactory(kunstruct.NewKunstructuredFactoryImpl()), transformer.NewFactoryImpl())
pc := plugins.DefaultPluginConfig()
kt, err := target.NewKustTarget(_loader, rf, transformer.NewFactoryImpl(), plugins.NewLoader(pc, rf))
if err != nil {
th.t.Fatalf("Unexpected construction error %v", err)
}
actual, err := kt.MakeCustomizedResMap()
if err != nil {
t.Fatalf("Err: %v", err)
}
th.assertActualEqualsExpected(actual, string(expected))
}