GalleyBytes / terraform-operator

A Kubernetes CRD to handle terraform operations
http://tf.galleybytes.com
Apache License 2.0
364 stars 47 forks source link

openapi errors during build #74

Closed Cytrian closed 2 years ago

Cytrian commented 2 years ago

When building the terraform-operator locally, I always get build errors regarding the generated openapi.

To have a clean and reproducible build environment, I used this Dockerfile.build:

FROM golang:1.15-alpine AS build
RUN apk add make git gcc libc-dev
WORKDIR /src
COPY . .
RUN make

After

git checkout v0.5.1
docker build . -f Dockerfile.build 

openapi-gen produces these errors:

/go/bin/openapi-gen --logtostderr=true -o "" -i ./pkg/apis/tf/v1alpha1 -O zz_generated.openapi -p ./pkg/apis/tf/v1alpha1 -h ./hack/boilerplate.go.txt -r "-"
API rule violation: list_type_missing,./pkg/apis/tf/v1alpha1,TerraformSpec,Credentials
API rule violation: list_type_missing,./pkg/apis/tf/v1alpha1,TerraformSpec,Env
API rule violation: list_type_missing,./pkg/apis/tf/v1alpha1,TerraformSpec,OutputsToInclude
API rule violation: list_type_missing,./pkg/apis/tf/v1alpha1,TerraformSpec,OutputsToOmit
API rule violation: list_type_missing,./pkg/apis/tf/v1alpha1,TerraformSpec,ResourceDownloads
API rule violation: list_type_missing,./pkg/apis/tf/v1alpha1,TerraformSpec,RunnerRules
API rule violation: list_type_missing,./pkg/apis/tf/v1alpha1,TerraformSpec,SCMAuthMethods
API rule violation: list_type_missing,./pkg/apis/tf/v1alpha1,TerraformStatus,Stages

Later on, go refuses to compile and exits:

# github.com/isaaguilar/terraform-operator/pkg/apis/tf/v1alpha1
pkg/apis/tf/v1alpha1/zz_generated.openapi.go:40:3: cannot use "k8s.io/kube-openapi/pkg/validation/spec".Schema literal (type "k8s.io/kube-openapi/pkg/validation/spec".Schema) as type "github.com/go-openapi/spec".Schema in field value
pkg/apis/tf/v1alpha1/zz_generated.openapi.go:62:8: cannot use ref("k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta") (type "github.com/go-openapi/spec".Ref) as type "k8s.io/kube-openapi/pkg/validation/spec".Ref in field value
pkg/apis/tf/v1alpha1/zz_generated.openapi.go:68:8: cannot use ref("./pkg/apis/tf/v1alpha1.TerraformSpec") (type "github.com/go-openapi/spec".Ref) as type "k8s.io/kube-openapi/pkg/validation/spec".Ref in field value
pkg/apis/tf/v1alpha1/zz_generated.openapi.go:74:8: cannot use ref("./pkg/apis/tf/v1alpha1.TerraformStatus") (type "github.com/go-openapi/spec".Ref) as type "k8s.io/kube-openapi/pkg/validation/spec".Ref in field value
pkg/apis/tf/v1alpha1/zz_generated.openapi.go:107:11: cannot use ref("k8s.io/api/rbac/v1.PolicyRule") (type "github.com/go-openapi/spec".Ref) as type "k8s.io/kube-openapi/pkg/validation/spec".Ref in field value
pkg/apis/tf/v1alpha1/zz_generated.openapi.go:170:8: cannot use ref("k8s.io/api/core/v1.ConfigMapKeySelector") (type "github.com/go-openapi/spec".Ref) as type "k8s.io/kube-openapi/pkg/validation/spec".Ref in field value
pkg/apis/tf/v1alpha1/zz_generated.openapi.go:176:8: cannot use ref("k8s.io/api/core/v1.ConfigMapKeySelector") (type "github.com/go-openapi/spec".Ref) as type "k8s.io/kube-openapi/pkg/validation/spec".Ref in field value
pkg/apis/tf/v1alpha1/zz_generated.openapi.go:182:8: cannot use ref("k8s.io/api/core/v1.ConfigMapKeySelector") (type "github.com/go-openapi/spec".Ref) as type "k8s.io/kube-openapi/pkg/validation/spec".Ref in field value
pkg/apis/tf/v1alpha1/zz_generated.openapi.go:214:8: cannot use ref("./pkg/apis/tf/v1alpha1.ConfigMapSelector") (type "github.com/go-openapi/spec".Ref) as type "k8s.io/kube-openapi/pkg/validation/spec".Ref in field value
pkg/apis/tf/v1alpha1/zz_generated.openapi.go:275:11: cannot use ref("./pkg/apis/tf/v1alpha1.ResourceDownload") (type "github.com/go-openapi/spec".Ref) as type "k8s.io/kube-openapi/pkg/validation/spec".Ref in field value
pkg/apis/tf/v1alpha1/zz_generated.openapi.go:275:11: too many errors

What am I doing wrong here, how can I build terraform-operator?

Cytrian commented 2 years ago

Found out, the "API rule violations" are probably only warnings. I was able to build the operator locally after doing some updates:

I'm not a good go developer, but that's what worked for me. The "violations" still appear, but the controller can be built.

See here: https://github.com/Cytrian/terraform-operator/commit/cdd80e7599d6f5ecd58afc2ca01ff467cf19870b

isaaguilar commented 2 years ago

Thanks so much for this @Cytrian !Worked like a charm!