vault-config-operator icon indicating copy to clipboard operation
vault-config-operator copied to clipboard

Following documentation to contribute new Vault API does not seem to work

Open yann-soubeyrand opened this issue 9 months ago • 0 comments

Hello,

I have tried to follow the documentation to bootstrap a new Vault API (https://github.com/redhat-cop/vault-config-operator/blob/main/docs/contributing-vault-apis.md), but it did not work for me.

I first tried with the latest operator-sdk version (v1.39.1), but it seems that this version does not support kubebuilder v3 projects:

❯ operator-sdk create api --group redhatcop --version v1alpha1 --kind CertAuthEngineConfig --resource --controller
Error: no plugin could be resolved with key "go.kubebuilder.io/v3" for project version "3"
Usage:
  operator-sdk [flags]

Examples:
The first step is to initialize your project:
    operator-sdk init [--plugins=<PLUGIN KEYS> [--project-version=<PROJECT VERSION>]]

<PLUGIN KEYS> is a comma-separated list of plugin keys from the following table
and <PROJECT VERSION> a supported project version for these plugins.

                             Plugin keys | Supported project versions
-----------------------------------------+----------------------------
     ansible.sdk.operatorframework.io/v1 |                          3
 deploy-image.go.kubebuilder.io/v1-alpha |                          3
                    go.kubebuilder.io/v4 |                          3
         grafana.kubebuilder.io/v1-alpha |                          3
        helm.sdk.operatorframework.io/v1 |                          3

For more specific help for the init command of a certain plugins and project version
configuration please run:
    operator-sdk init --help --plugins=<PLUGIN KEYS> [--project-version=<PROJECT VERSION>]

Default plugin keys: "go.kubebuilder.io/v4"
Default project version: "3"


Flags:
  -h, --help                     help for operator-sdk
      --plugins strings          plugin keys to be used for this subcommand execution
      --project-version string   project version (default "3")

FATA[0000] no plugin could be resolved with key "go.kubebuilder.io/v3" for project version "3" 

I then tried to use previous versions of the operator-sdk, but it did not work either (it seems to be due to https://github.com/kubernetes-sigs/controller-tools/issues/851):

❯ operator-sdk create api --group redhatcop --version v1alpha1 --kind CertAuthEngineConfig --resource --controller
[Deprecation Notice] This version is deprecated.The `go/v3` cannot scaffold projects using kustomize versions v4x+ and cannot fully support Kubernetes 1.25+.It is recommended to upgrade your project to the latest versions available (go/v4).Please, check the migration guide to learn how to upgrade your project

INFO[0000] Writing kustomize manifests for you to edit... 
INFO[0000] Writing scaffold for you to edit...          
INFO[0000] api/v1alpha1/certauthengineconfig_types.go   
INFO[0000] controllers/certauthengineconfig_controller.go 
INFO[0000] Update dependencies:
$ go mod tidy           
INFO[0000] Running make:
$ make generate                
mkdir -p /home/yann/Projets/Professionnel/kubernetes/vault-config-operator/bin
test -s /home/yann/Projets/Professionnel/kubernetes/vault-config-operator/bin/controller-gen || echo "Downloading controller-gen to /home/yann/Projets/Professionnel/kubernetes/vault-config-operator/bin/controller-gen..." && GOBIN=/home/yann/Projets/Professionnel/kubernetes/vault-config-operator/bin go install sigs.k8s.io/controller-tools/cmd/[email protected]
Downloading controller-gen to /home/yann/Projets/Professionnel/kubernetes/vault-config-operator/bin/controller-gen...
/home/yann/Projets/Professionnel/kubernetes/vault-config-operator/bin/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xa40c2f]

goroutine 146 [running]:
go/types.(*Checker).handleBailout(0xc000507340, 0xc000a39d60)
	/usr/lib/golang/src/go/types/check.go:404 +0x88
panic({0xc00400?, 0x13240e0?})
	/usr/lib/golang/src/runtime/panic.go:785 +0x132
go/types.(*StdSizes).Sizeof(0x0, {0xe03800, 0x132ca80})
	/usr/lib/golang/src/go/types/sizes.go:229 +0x30f
go/types.(*Config).sizeof(...)
	/usr/lib/golang/src/go/types/sizes.go:334
go/types.representableConst.func1({0xe03800?, 0x132ca80?})
	/usr/lib/golang/src/go/types/const.go:77 +0x86
go/types.representableConst({0xe0a170, 0x12f8960}, 0xc000507340, 0x132ca80, 0x0)
	/usr/lib/golang/src/go/types/const.go:93 +0x173
go/types.(*Checker).arrayLength(0xc000507340, {0xe08520, 0xc000ab41e0?})
	/usr/lib/golang/src/go/types/typexpr.go:537 +0x1db
go/types.(*Checker).typInternal(0xc000507340, {0xe06b40, 0xc000814720}, 0x0)
	/usr/lib/golang/src/go/types/typexpr.go:320 +0x4b5
go/types.(*Checker).definedType(0xc000507340, {0xe06b40, 0xc000814720}, 0xe0fe40?)
	/usr/lib/golang/src/go/types/typexpr.go:201 +0x2f
go/types.(*Checker).varType(0xc000507340, {0xe06b40, 0xc000814720})
	/usr/lib/golang/src/go/types/typexpr.go:166 +0x25
go/types.(*Checker).structType(0xc000507340, 0xc000b433e0, 0xc000b433e0?)
	/usr/lib/golang/src/go/types/struct.go:114 +0x18a
go/types.(*Checker).typInternal(0xc000507340, {0xe06ab0, 0xc000c1aa08}, 0xc000b34dc0)
	/usr/lib/golang/src/go/types/typexpr.go:337 +0xf45
go/types.(*Checker).definedType(0xc000507340, {0xe06ab0, 0xc000c1aa08}, 0xcd0fb8?)
	/usr/lib/golang/src/go/types/typexpr.go:201 +0x2f
go/types.(*Checker).typeDecl(0xc000507340, 0xc000b34dc0, 0xc000ab2600, 0x0)
	/usr/lib/golang/src/go/types/decl.go:649 +0x4e8
go/types.(*Checker).objDecl(0xc000507340, {0xe0fe40, 0xc000b34dc0}, 0x0)
	/usr/lib/golang/src/go/types/decl.go:191 +0xa3f
go/types.(*Checker).packageObjects(0xc000507340)
	/usr/lib/golang/src/go/types/resolver.go:702 +0x3a5
go/types.(*Checker).checkFiles(0xc000507340, {0xc000866648, 0x3, 0x3})
	/usr/lib/golang/src/go/types/check.go:459 +0x15a
go/types.(*Checker).Files(0xc000342920?, {0xc000866648?, 0xc0000a9560?, 0x6?})
	/usr/lib/golang/src/go/types/check.go:422 +0x75
sigs.k8s.io/controller-tools/pkg/loader.(*loader).typeCheck(0xc0003472c0, 0xc00014e0e0)
	/home/yann/Projets/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/loader/loader.go:286 +0x36a
sigs.k8s.io/controller-tools/pkg/loader.(*Package).NeedTypesInfo(0xc00014e0e0)
	/home/yann/Projets/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/loader/loader.go:99 +0x39
sigs.k8s.io/controller-tools/pkg/loader.(*TypeChecker).check(0xc000a41c20, 0xc00014e0e0)
	/home/yann/Projets/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/loader/refs.go:268 +0x2b2
sigs.k8s.io/controller-tools/pkg/loader.(*TypeChecker).check.func1(0x5a?)
	/home/yann/Projets/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/loader/refs.go:262 +0x4d
created by sigs.k8s.io/controller-tools/pkg/loader.(*TypeChecker).check in goroutine 82
	/home/yann/Projets/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/loader/refs.go:260 +0x1bc
make: *** [Makefile:114: generate] Error 2
Error: failed to create API: unable to run post-scaffold tasks of "base.go.kubebuilder.io/v3": exit status 2
Usage:
  operator-sdk create api [flags]

Examples:
  # Create a frigates API with Group: ship, Version: v1beta1 and Kind: Frigate
  operator-sdk create api --group ship --version v1beta1 --kind Frigate

  # Edit the API Scheme
  nano api/v1beta1/frigate_types.go

  # Edit the Controller
  nano controllers/frigate/frigate_controller.go

  # Edit the Controller Test
  nano controllers/frigate/frigate_controller_test.go

  # Generate the manifests
  make manifests

  # Install CRDs into the Kubernetes cluster using kubectl apply
  make install

  # Regenerate code and run against the Kubernetes cluster configured by ~/.kube/config
  make run


Flags:
      --controller           if set, generate the controller without prompting the user (default true)
      --force                attempt to create resource even if it already exists
      --group string         resource Group
  -h, --help                 help for api
      --kind string          resource Kind
      --make make generate   if true, run make generate after generating files (default true)
      --namespaced           resource is namespaced (default true)
      --plural string        resource irregular plural form
      --resource             if set, generate the resource without prompting the user (default true)
      --version string       resource Version

Global Flags:
      --plugins strings   plugin keys to be used for this subcommand execution
      --verbose           Enable verbose logging

FATA[0003] failed to create API: unable to run post-scaffold tasks of "base.go.kubebuilder.io/v3": exit status 2 

As a workaround, I used a previous version of operator-sdk and set the GOTOOLCHAIN environment variable to go1.21.8 (the one used in go.mod).

yann-soubeyrand avatar Jan 16 '25 13:01 yann-soubeyrand