Converting NetworkPolicy results in k2tf panic
landro opened this issue · 2 comments
landro commented
Officially documented default deny NetworkPolicy results in: panic: runtime error: index out of range
This is the policy in question:
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default-deny
spec:
podSelector: {}
policyTypes:
- Ingress
- Egress
iptizer commented
Same here, my example:
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default-deny-all
spec:
podSelector: {}
My system data:
- MacOs
- Installed from GitHub release k2tf_0.2.5_Darwin_x86_64.tar.gz
I'd be welcome to post more examples. Executing with debug the following is printed:
cat tmp.yaml| k2tf -d > network_policies.tf ✔ 2591 16:10:13
4:10PM Debug | starting k2tf builddate=2019-07-31T03:35:06Z commit=120e22f0db699dec9d0c0c6d3bc29538a1283e1e version=0.2.5
4:10PM Debug | read 1 objects from input
4:10PM Debug | outputting HCL to Stdout
4:10PM Debug | entering WalkLoc name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | entering Struct name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | opening hclBlock for field: kubernetes_network_policy name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | ignoring TypeMeta name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | fieldPush ObjectMeta field=ObjectMeta name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | entering StructField field=ObjectMeta name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | entering Struct field=ObjectMeta name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | sliceElemType field=ObjectMeta name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | sliceType nil field=ObjectMeta name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | creating block [metadata] for field [ObjectMeta] field=ObjectMeta name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | opening hclBlock for field: metadata field=ObjectMeta name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | fieldPush Name field=Name name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | entering StructField field=Name name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | Primitive: Name = default-deny-all (string) field=Name name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | processing Name (string) field=Name name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | fieldPop Name field=ObjectMeta name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | exiting StructField field=ObjectMeta name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | fieldPush GenerateName field=GenerateName name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | entering StructField field=GenerateName name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | Primitive: GenerateName = (string) field=GenerateName name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | fieldPop GenerateName field=ObjectMeta name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | exiting StructField field=ObjectMeta name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | fieldPush Namespace field=Namespace name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | entering StructField field=Namespace name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | Primitive: Namespace = (string) field=Namespace name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | fieldPop Namespace field=ObjectMeta name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | exiting StructField field=ObjectMeta name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | ignoring SelfLink field=ObjectMeta name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | ignoring UID field=ObjectMeta name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | ignoring ResourceVersion field=ObjectMeta name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | ignoring Generation field=ObjectMeta name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | ignoring CreationTimestamp field=ObjectMeta name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | ignoring DeletionTimestamp field=ObjectMeta name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | fieldPush DeletionGracePeriodSeconds field=DeletionGracePeriodSeconds name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | entering StructField field=DeletionGracePeriodSeconds name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | fieldPop DeletionGracePeriodSeconds field=ObjectMeta name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | exiting StructField field=ObjectMeta name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | fieldPush Labels field=Labels name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | entering StructField field=Labels name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | entering Map field=Labels name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | opening hclBlock for field: labels field=Labels name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | closing hclBlock: labels field=Labels name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | exiting Map field=Labels name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | fieldPop Labels field=ObjectMeta name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | exiting StructField field=ObjectMeta name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | fieldPush Annotations field=Annotations name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | entering StructField field=Annotations name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | entering Map field=Annotations name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | opening hclBlock for field: annotations field=Annotations name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | closing hclBlock: annotations field=Annotations name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | exiting Map field=Annotations name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | fieldPop Annotations field=ObjectMeta name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | exiting StructField field=ObjectMeta name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | ignoring OwnerReferences field=ObjectMeta name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | fieldPush Initializers field=Initializers name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | entering StructField field=Initializers name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | fieldPop Initializers field=ObjectMeta name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | exiting StructField field=ObjectMeta name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | fieldPush Finalizers field=Finalizers name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | entering StructField field=Finalizers name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | entering Slice field=Finalizers name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | slicePush Finalizers field=Finalizers name=default_deny_all slice=Finalizers type=kubernetes_network_policy
4:10PM Debug | setting setCurrentSlice to Finalizers field=Finalizers name=default_deny_all slice=Finalizers type=kubernetes_network_policy
4:10PM Debug | skipping empty slice field=Finalizers name=default_deny_all slice=Finalizers type=kubernetes_network_policy
4:10PM Debug | slicePop Finalizers field=Finalizers name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | setting setCurrentSlice to Finalizers field=Finalizers name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | exiting Slice field=Finalizers name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | fieldPop Finalizers field=ObjectMeta name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | exiting StructField field=ObjectMeta name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | fieldPush ClusterName field=ClusterName name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | entering StructField field=ClusterName name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | Primitive: ClusterName = (string) field=ClusterName name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | fieldPop ClusterName field=ObjectMeta name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | exiting StructField field=ObjectMeta name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | fieldPush ManagedFields field=ManagedFields name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | entering StructField field=ManagedFields name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | entering Slice field=ManagedFields name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | slicePush ManagedFields field=ManagedFields name=default_deny_all slice=ManagedFields type=kubernetes_network_policy
4:10PM Debug | setting setCurrentSlice to ManagedFields field=ManagedFields name=default_deny_all slice=ManagedFields type=kubernetes_network_policy
4:10PM Debug | skipping empty slice field=ManagedFields name=default_deny_all slice=ManagedFields type=kubernetes_network_policy
4:10PM Debug | slicePop ManagedFields field=ManagedFields name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | setting setCurrentSlice to ManagedFields field=ManagedFields name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | exiting Slice field=ManagedFields name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | fieldPop ManagedFields field=ObjectMeta name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | exiting StructField field=ObjectMeta name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | closing hclBlock: metadata field=ObjectMeta name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | exiting Struct field=ObjectMeta name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | fieldPop ObjectMeta name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | exiting StructField name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | fieldPush Spec field=Spec name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | entering StructField field=Spec name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | entering Struct field=Spec name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | sliceElemType field=Spec name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | sliceType nil field=Spec name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | creating block [spec] for field [Spec] field=Spec name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | opening hclBlock for field: spec field=Spec name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | fieldPush PodSelector field=PodSelector name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | entering StructField field=PodSelector name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | entering Struct field=PodSelector name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | sliceElemType field=PodSelector name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | sliceType nil field=PodSelector name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | creating block [pod_selector] for field [PodSelector] field=PodSelector name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | opening hclBlock for field: pod_selector field=PodSelector name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | fieldPush MatchLabels field=MatchLabels name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | entering StructField field=MatchLabels name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | entering Map field=MatchLabels name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | opening hclBlock for field: match_labels field=MatchLabels name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | closing hclBlock: match_labels field=MatchLabels name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | exiting Map field=MatchLabels name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | fieldPop MatchLabels field=PodSelector name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | exiting StructField field=PodSelector name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | fieldPush MatchExpressions field=MatchExpressions name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | entering StructField field=MatchExpressions name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | entering Slice field=MatchExpressions name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | slicePush MatchExpressions field=MatchExpressions name=default_deny_all slice=MatchExpressions type=kubernetes_network_policy
4:10PM Debug | setting setCurrentSlice to MatchExpressions field=MatchExpressions name=default_deny_all slice=MatchExpressions type=kubernetes_network_policy
4:10PM Debug | skipping empty slice field=MatchExpressions name=default_deny_all slice=MatchExpressions type=kubernetes_network_policy
4:10PM Debug | slicePop MatchExpressions field=MatchExpressions name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | setting setCurrentSlice to MatchExpressions field=MatchExpressions name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | exiting Slice field=MatchExpressions name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | fieldPop MatchExpressions field=PodSelector name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | exiting StructField field=PodSelector name=default_deny_all type=kubernetes_network_policy
4:10PM Debug | closing hclBlock: pod_selector field=PodSelector name=default_deny_all type=kubernetes_network_policy
panic: runtime error: index out of range
goroutine 1 [running]:
github.com/sl1pm4t/k2tf/pkg/tfkschema.search(0xc000633740, 0xc000441750, 0x0, 0x0, 0x0)
/drone/src/pkg/tfkschema/schema.go:78 +0x2e1
github.com/sl1pm4t/k2tf/pkg/tfkschema.IsAttributeRequired(0xc000248f61, 0x19, 0x19)
/drone/src/pkg/tfkschema/schema.go:68 +0x7e
main.(*hclBlock).isRequired(0xc0000f02c0, 0x1e)
/drone/src/hcl_block.go:115 +0x47
main.(*hclBlock).isRequired(0xc000077000, 0x2b)
/drone/src/hcl_block.go:117 +0x82
main.(*hclBlock).isRequired(0xc0001c9480, 0x27d844f)
/drone/src/hcl_block.go:117 +0x82
main.(*ObjectWalker).closeBlock(0xc0003ebce0, 0x27c9939)
/drone/src/hcl_writer.go:207 +0x2c8
main.(*ObjectWalker).Exit(0xc0003ebce0, 0x8, 0x0, 0x0)
/drone/src/hcl_writer.go:253 +0x48
github.com/mitchellh/reflectwalk.walkStruct(0x2648fc0, 0xc0003aafc0, 0x199, 0x2787820, 0xc0003ebce0, 0x0, 0x2541007)
/go/pkg/mod/github.com/mitchellh/reflectwalk@v1.0.0/reflectwalk.go:397 +0x4c6
github.com/mitchellh/reflectwalk.walk(0x2648fc0, 0xc0003aafc0, 0x199, 0x2787820, 0xc0003ebce0, 0x2bdcc01, 0x2648fc0)
/go/pkg/mod/github.com/mitchellh/reflectwalk@v1.0.0/reflectwalk.go:188 +0x571
github.com/mitchellh/reflectwalk.walkStruct(0x26bc780, 0xc0003aafc0, 0x199, 0x2787820, 0xc0003ebce0, 0x0, 0x24c8c62)
/go/pkg/mod/github.com/mitchellh/reflectwalk@v1.0.0/reflectwalk.go:385 +0x3d5
github.com/mitchellh/reflectwalk.walk(0x26bc780, 0xc0003aafc0, 0x199, 0x2787820, 0xc0003ebce0, 0x2bdcc01, 0x26bc780)
/go/pkg/mod/github.com/mitchellh/reflectwalk@v1.0.0/reflectwalk.go:188 +0x571
github.com/mitchellh/reflectwalk.walkStruct(0x26918a0, 0xc0003aaea0, 0x199, 0x2787820, 0xc0003ebce0, 0x100, 0xc00063d060)
/go/pkg/mod/github.com/mitchellh/reflectwalk@v1.0.0/reflectwalk.go:385 +0x3d5
github.com/mitchellh/reflectwalk.walk(0x27acea0, 0xc0003aaea0, 0x16, 0x2787820, 0xc0003ebce0, 0x23cff01, 0x2756300)
/go/pkg/mod/github.com/mitchellh/reflectwalk@v1.0.0/reflectwalk.go:188 +0x571
github.com/mitchellh/reflectwalk.Walk(0x27acea0, 0xc0003aaea0, 0x2787820, 0xc0003ebce0, 0x0, 0x0)
/go/pkg/mod/github.com/mitchellh/reflectwalk@v1.0.0/reflectwalk.go:92 +0x182
main.WriteObject(0x2b6d140, 0xc0003aaea0, 0xc0005c0d00, 0xc0002b7f48, 0x1, 0x1)
/drone/src/hcl_writer.go:30 +0x89
main.main()
/drone/src/main.go:62 +0x2b6