Skip to content

Commit 71a7a7d

Browse files
re-enabled TestFnContainerGenerator with enable-gcp-services
1 parent 436a047 commit 71a7a7d

File tree

1 file changed

+30
-195
lines changed

1 file changed

+30
-195
lines changed

api/krusty/fnplugin_test.go

Lines changed: 30 additions & 195 deletions
Original file line numberDiff line numberDiff line change
@@ -504,213 +504,49 @@ 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(".", `
514-
resources:
515-
- short_secret.yaml
509+
o := th.MakeOptionsPluginsEnabled()
510+
fSys := filesys.MakeFsOnDisk()
511+
b := MakeKustomizer(&o)
512+
tmpDir, err := filesys.NewTmpConfirmedDir()
513+
assert.NoError(t, err)
514+
assert.NoError(t, fSys.WriteFile(filepath.Join(tmpDir.String(), "kustomization.yaml"), []byte(`
516515
generators:
517-
- gener.yaml
518-
`)
519-
// Create generator config
520-
th.WriteF("gener.yaml", `
521-
apiVersion: examples.config.kubernetes.io/v1beta1
522-
kind: CockroachDB
516+
- project-service-set.yaml
517+
`)))
518+
assert.NoError(t, fSys.WriteFile(filepath.Join(tmpDir.String(), "project-service-set.yaml"), []byte(`
519+
apiVersion: blueprints.cloud.google.com/v1alpha1
520+
kind: ProjectServiceSet
523521
metadata:
524522
name: demo
525523
annotations:
526524
config.kubernetes.io/function: |
527525
container:
528-
image: gcr.io/kustomize-functions/example-cockroachdb:v0.1.0
529-
spec:
530-
replicas: 3
531-
`)
532-
// Create some additional resource just to make sure everything is added
533-
th.WriteF("short_secret.yaml", `
534-
apiVersion: v1
535-
kind: Secret
536-
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
545-
`)
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
526+
image: gcr.io/kpt-fn/enable-gcp-services:v0.1.0
567527
spec:
568-
minAvailable: 67%
569-
selector:
570-
matchLabels:
571-
app: cockroachdb
572-
name: demo
573-
---
574-
apiVersion: v1
575-
kind: Service
576-
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
592-
---
593-
apiVersion: v1
528+
services:
529+
- compute.googleapis.com
530+
projectID: foo
531+
`)))
532+
m, err := b.Run(fSys, tmpDir.String())
533+
assert.NoError(t, err)
534+
actual, err := m.AsYaml()
535+
assert.NoError(t, err)
536+
assert.Equal(t, `apiVersion: serviceusage.cnrm.cloud.google.com/v1beta1
594537
kind: Service
595538
metadata:
596539
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
540+
blueprints.cloud.google.com/ownerReference: blueprints.cloud.google.com/ProjectServiceSet/demo
541+
config.kubernetes.io/function: |
542+
container:
543+
image: gcr.io/kpt-fn/enable-gcp-services:v0.1.0
544+
name: demo-compute
625545
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-
`)
546+
projectRef:
547+
external: foo
548+
resourceID: compute.googleapis.com
549+
`, string(actual))
714550
}
715551

716552
func TestFnContainerTransformer(t *testing.T) {
@@ -733,7 +569,6 @@ kind: Deployment
733569
metadata:
734570
name: foo
735571
`)))
736-
737572
assert.NoError(t, fSys.WriteFile(filepath.Join(tmpDir.String(), "e2econtainerconfig.yaml"), []byte(`
738573
apiVersion: example.com/v1alpha1
739574
kind: Input

0 commit comments

Comments
 (0)