Skip to content

Commit d3184da

Browse files
authored
Merge pull request #5111 from yutaroyamanaka/reenable-skipped-tests
Re-enable tests disabled in #3880
2 parents eadb469 + 2649d39 commit d3184da

File tree

1 file changed

+59
-266
lines changed

1 file changed

+59
-266
lines changed

api/krusty/fnplugin_test.go

Lines changed: 59 additions & 266 deletions
Original file line numberDiff line numberDiff line change
@@ -504,313 +504,106 @@ func skipIfNoDocker(t *testing.T) {
504504
}
505505

506506
func TestFnContainerGenerator(t *testing.T) {
507-
t.Skip("wait for #3881")
508507
skipIfNoDocker(t)
509-
510-
// Function plugins should not need the env setup done by MakeEnhancedHarness
511508
th := kusttest_test.MakeHarness(t)
512-
513-
th.WriteK(".", `
509+
o := th.MakeOptionsPluginsEnabled()
510+
tmpDir, err := filesys.NewTmpConfirmedDir()
511+
assert.NoError(t, err)
512+
th.WriteK(tmpDir.String(), `
514513
resources:
515-
- short_secret.yaml
514+
- deployment.yaml
516515
generators:
517-
- gener.yaml
516+
- project-service-set.yaml
518517
`)
519518
// Create generator config
520-
th.WriteF("gener.yaml", `
521-
apiVersion: examples.config.kubernetes.io/v1beta1
522-
kind: CockroachDB
519+
th.WriteF(filepath.Join(tmpDir.String(), "project-service-set.yaml"), `
520+
apiVersion: blueprints.cloud.google.com/v1alpha1
521+
kind: ProjectServiceSet
523522
metadata:
524523
name: demo
525524
annotations:
526525
config.kubernetes.io/function: |
527526
container:
528-
image: gcr.io/kustomize-functions/example-cockroachdb:v0.1.0
527+
image: gcr.io/kpt-fn/enable-gcp-services:v0.1.0
529528
spec:
530-
replicas: 3
529+
services:
530+
- compute.googleapis.com
531+
projectID: foo
531532
`)
532-
// Create some additional resource just to make sure everything is added
533-
th.WriteF("short_secret.yaml", `
534-
apiVersion: v1
535-
kind: Secret
533+
// Create another resource just to make sure everything is added
534+
th.WriteF(filepath.Join(tmpDir.String(), "deployment.yaml"), `
535+
apiVersion: apps/v1
536+
kind: Deployment
536537
metadata:
537-
labels:
538-
airshipit.org/ephemeral-user-data: "true"
539-
name: node1-bmc-secret
540-
type: Opaque
541-
stringData:
542-
userData: |
543-
bootcmd:
544-
- mkdir /mnt/vda
538+
name: foo
545539
`)
546-
m := th.Run(".", th.MakeOptionsPluginsEnabled())
547-
th.AssertActualEqualsExpected(m, `
548-
apiVersion: v1
549-
kind: Secret
550-
metadata:
551-
labels:
552-
airshipit.org/ephemeral-user-data: "true"
553-
name: node1-bmc-secret
554-
stringData:
555-
userData: |
556-
bootcmd:
557-
- mkdir /mnt/vda
558-
type: Opaque
559-
---
560-
apiVersion: policy/v1beta1
561-
kind: PodDisruptionBudget
562-
metadata:
563-
labels:
564-
app: cockroachdb
565-
name: demo
566-
name: demo-budget
567-
spec:
568-
minAvailable: 67%
569-
selector:
570-
matchLabels:
571-
app: cockroachdb
572-
name: demo
573-
---
574-
apiVersion: v1
575-
kind: Service
540+
m := th.Run(tmpDir.String(), o)
541+
actual, err := m.AsYaml()
542+
assert.NoError(t, err)
543+
assert.Equal(t, `apiVersion: apps/v1
544+
kind: Deployment
576545
metadata:
577-
labels:
578-
app: cockroachdb
579-
name: demo
580-
name: demo-public
581-
spec:
582-
ports:
583-
- name: grpc
584-
port: 26257
585-
targetPort: 26257
586-
- name: http
587-
port: 8080
588-
targetPort: 8080
589-
selector:
590-
app: cockroachdb
591-
name: demo
546+
name: foo
592547
---
593-
apiVersion: v1
548+
apiVersion: serviceusage.cnrm.cloud.google.com/v1beta1
594549
kind: Service
595550
metadata:
596551
annotations:
597-
prometheus.io/path: _status/vars
598-
prometheus.io/port: "8080"
599-
prometheus.io/scrape: "true"
600-
service.alpha.kubernetes.io/tolerate-unready-endpoints: "true"
601-
labels:
602-
app: cockroachdb
603-
name: demo
604-
name: demo
605-
spec:
606-
clusterIP: None
607-
ports:
608-
- name: grpc
609-
port: 26257
610-
targetPort: 26257
611-
- name: http
612-
port: 8080
613-
targetPort: 8080
614-
selector:
615-
app: cockroachdb
616-
name: demo
617-
---
618-
apiVersion: apps/v1
619-
kind: StatefulSet
620-
metadata:
621-
labels:
622-
app: cockroachdb
623-
name: demo
624-
name: demo
552+
blueprints.cloud.google.com/ownerReference: blueprints.cloud.google.com/ProjectServiceSet/demo
553+
config.kubernetes.io/function: |
554+
container:
555+
image: gcr.io/kpt-fn/enable-gcp-services:v0.1.0
556+
name: demo-compute
625557
spec:
626-
replicas: 3
627-
selector:
628-
matchLabels:
629-
app: cockroachdb
630-
name: demo
631-
serviceName: demo
632-
template:
633-
metadata:
634-
labels:
635-
app: cockroachdb
636-
name: demo
637-
spec:
638-
affinity:
639-
podAntiAffinity:
640-
preferredDuringSchedulingIgnoredDuringExecution:
641-
- podAffinityTerm:
642-
labelSelector:
643-
matchExpressions:
644-
- key: app
645-
operator: In
646-
values:
647-
- cockroachdb
648-
topologyKey: kubernetes.io/hostname
649-
weight: 100
650-
containers:
651-
- command:
652-
- /bin/bash
653-
- -ecx
654-
- |
655-
# The use of qualified `+"`hostname -f`"+` is crucial:
656-
# Other nodes aren't able to look up the unqualified hostname.
657-
CRARGS=("start" "--logtostderr" "--insecure" "--host" "$(hostname -f)" "--http-host" "0.0.0.0")
658-
# We only want to initialize a new cluster (by omitting the join flag)
659-
# if we're sure that we're the first node (i.e. index 0) and that
660-
# there aren't any other nodes running as part of the cluster that
661-
# this is supposed to be a part of (which indicates that a cluster
662-
# already exists and we should make sure not to create a new one).
663-
# It's fine to run without --join on a restart if there aren't any
664-
# other nodes.
665-
if [ ! "$(hostname)" == "cockroachdb-0" ] || [ -e "/cockroach/cockroach-data/cluster_exists_marker" ]
666-
then
667-
# We don't join cockroachdb in order to avoid a node attempting
668-
# to join itself, which currently doesn't work
669-
# (https://github.com/cockroachdb/cockroach/issues/9625).
670-
CRARGS+=("--join" "cockroachdb-public")
671-
fi
672-
exec /cockroach/cockroach ${CRARGS[*]}
673-
image: cockroachdb/cockroach:v1.1.0
674-
imagePullPolicy: IfNotPresent
675-
name: demo
676-
ports:
677-
- containerPort: 26257
678-
name: grpc
679-
- containerPort: 8080
680-
name: http
681-
volumeMounts:
682-
- mountPath: /cockroach/cockroach-data
683-
name: datadir
684-
initContainers:
685-
- args:
686-
- -on-start=/on-start.sh
687-
- -service=cockroachdb
688-
env:
689-
- name: POD_NAMESPACE
690-
valueFrom:
691-
fieldRef:
692-
fieldPath: metadata.namespace
693-
image: cockroachdb/cockroach-k8s-init:0.1
694-
imagePullPolicy: IfNotPresent
695-
name: bootstrap
696-
volumeMounts:
697-
- mountPath: /cockroach/cockroach-data
698-
name: datadir
699-
terminationGracePeriodSeconds: 60
700-
volumes:
701-
- name: datadir
702-
persistentVolumeClaim:
703-
claimName: datadir
704-
volumeClaimTemplates:
705-
- metadata:
706-
name: datadir
707-
spec:
708-
accessModes:
709-
- ReadWriteOnce
710-
resources:
711-
requests:
712-
storage: 1Gi
713-
`)
558+
projectRef:
559+
external: foo
560+
resourceID: compute.googleapis.com
561+
`, string(actual))
714562
}
715563

716564
func TestFnContainerTransformer(t *testing.T) {
717-
t.Skip("wait for #3881")
718565
skipIfNoDocker(t)
719-
720-
// Function plugins should not need the env setup done by MakeEnhancedHarness
721566
th := kusttest_test.MakeHarness(t)
722-
723-
th.WriteK(".", `
567+
o := th.MakeOptionsPluginsEnabled()
568+
tmpDir, err := filesys.NewTmpConfirmedDir()
569+
assert.NoError(t, err)
570+
th.WriteK(tmpDir.String(), `
724571
resources:
725-
- data.yaml
572+
- deployment.yaml
726573
transformers:
727-
- transf1.yaml
728-
- transf2.yaml
574+
- e2econtainerconfig.yaml
729575
`)
730-
731-
th.WriteF("data.yaml", `
576+
th.WriteF(filepath.Join(tmpDir.String(), "deployment.yaml"), `
732577
apiVersion: apps/v1
733578
kind: Deployment
734579
metadata:
735-
name: nginx
736-
labels:
737-
app: nginx
738-
annotations:
739-
tshirt-size: small # this injects the resource reservations
740-
spec:
741-
selector:
742-
matchLabels:
743-
app: nginx
744-
template:
745-
metadata:
746-
labels:
747-
app: nginx
748-
spec:
749-
containers:
750-
- name: nginx
751-
image: nginx
752-
`)
753-
// This transformer should add resource reservations based on annotation in data.yaml
754-
// See https://github.com/kubernetes-sigs/kustomize/tree/master/functions/examples/injection-tshirt-sizes
755-
th.WriteF("transf1.yaml", `
756-
apiVersion: examples.config.kubernetes.io/v1beta1
757-
kind: Validator
758-
metadata:
759-
name: valid
760-
annotations:
761-
config.kubernetes.io/function: |-
762-
container:
763-
image: gcr.io/kustomize-functions/example-tshirt:v0.2.0
580+
name: foo
764581
`)
765-
// This transformer will check resources without and won't do any changes
766-
// See https://github.com/kubernetes-sigs/kustomize/tree/master/functions/examples/validator-kubeval
767-
th.WriteF("transf2.yaml", `
768-
apiVersion: examples.config.kubernetes.io/v1beta1
769-
kind: Kubeval
582+
th.WriteF(filepath.Join(tmpDir.String(), "e2econtainerconfig.yaml"), `
583+
apiVersion: example.com/v1alpha1
584+
kind: Input
770585
metadata:
771-
name: validate
586+
name: foo
772587
annotations:
773588
config.kubernetes.io/function: |
774589
container:
775-
image: gcr.io/kustomize-functions/example-validator-kubeval:v0.1.0
776-
spec:
777-
strict: true
778-
ignoreMissingSchemas: true
779-
780-
# TODO: Update this to use network/volumes features.
781-
# Relevant issues:
782-
# - https://github.com/kubernetes-sigs/kustomize/issues/1901
783-
# - https://github.com/kubernetes-sigs/kustomize/issues/1902
784-
kubernetesVersion: "1.16.0"
785-
schemaLocation: "file:///schemas"
590+
image: "gcr.io/kustomize-functions/e2econtainerconfig"
786591
`)
787-
m := th.Run(".", th.MakeOptionsPluginsEnabled())
788-
th.AssertActualEqualsExpected(m, `
789-
apiVersion: apps/v1
592+
build := exec.Command("docker", "build", ".", "-t", "gcr.io/kustomize-functions/e2econtainerconfig")
593+
build.Dir = "../../cmd/config/internal/commands/e2e/e2econtainerconfig"
594+
assert.NoError(t, build.Run())
595+
m := th.Run(tmpDir.String(), o)
596+
actual, err := m.AsYaml()
597+
assert.NoError(t, err)
598+
assert.Equal(t, `apiVersion: apps/v1
790599
kind: Deployment
791600
metadata:
792601
annotations:
793-
tshirt-size: small
794-
labels:
795-
app: nginx
796-
name: nginx
797-
spec:
798-
selector:
799-
matchLabels:
800-
app: nginx
801-
template:
802-
metadata:
803-
labels:
804-
app: nginx
805-
spec:
806-
containers:
807-
- image: nginx
808-
name: nginx
809-
resources:
810-
requests:
811-
cpu: 200m
812-
memory: 50M
813-
`)
602+
a-bool-value: "false"
603+
a-int-value: "0"
604+
a-string-value: ""
605+
name: foo
606+
`, string(actual))
814607
}
815608

816609
func TestFnContainerTransformerWithConfig(t *testing.T) {

0 commit comments

Comments
 (0)