Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

operator-sdk generate openapi ignores +kubebuilder:printcolumn #1212

Closed
nrvnrvn opened this issue Mar 15, 2019 · 1 comment · Fixed by #1278
Closed

operator-sdk generate openapi ignores +kubebuilder:printcolumn #1212

nrvnrvn opened this issue Mar 15, 2019 · 1 comment · Fixed by #1278
Labels
kind/bug Categorizes issue or PR as related to a bug.

Comments

@nrvnrvn
Copy link

nrvnrvn commented Mar 15, 2019

Bug Report

What did you do?
added the following annotation:

// +kubebuilder:printcolumn:name="Replicas",type="integer",JSONPath=".spec.Replicas",description="The number of MyCoolCRD instances"
type MyCoolCRD struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`

	Spec   MyCoolCRDSpec   `json:"spec,omitempty"`
	Status MyCoolCRDStatus `json:"status,omitempty"`
}

What did you expect to see?
Expected to see it in the generated CRD.

What did you see instead? Under which circumstances?

$ GOFLAGS="-v" operator-sdk generate openapi
INFO[0001] Running OpenAPI code-generation for Custom Resource group versions: [k8s:[v1alpha1], ] 
2019/03/15 14:36:53 Code for OpenAPI definitions generated

[debug] name="Replicas"
[debug] type="integer"
[debug] JSONPath=".spec.Replicas"
[debug] description="The number of MyCoolCRD instances"INFO[0004] Created deploy/crds/k8s_v1alpha1_woot_crd.yaml 
INFO[0004] Code-generation complete. 

Environment

  • operator-sdk version:
    operator-sdk version v0.5.0+git

  • Kubernetes version information:

Client Version: version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.4", GitCommit:"c27b913fddd1a6c480c229191a087698aa92f0b1", GitTreeState:"clean", BuildDate:"2019-03-01T23:34:27Z", GoVersion:"go1.12", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.4", GitCommit:"c27b913fddd1a6c480c229191a087698aa92f0b1", GitTreeState:"clean", BuildDate:"2019-02-28T13:30:26Z", GoVersion:"go1.11.5", Compiler:"gc", Platform:"linux/amd64"}

  • Kubernetes cluster kind:

  • Are you writing your operator in ansible, helm, or go?
    go

Possible Solution

Additional context
If it is an upstream issue please advise the repo to report and probably to fix it. Kubebuilder looks great as a tool but it looks a bit immature at the same time. I've run in a number of issues possibly related to kubebuilder in a couple of days and don't want to flood here ) And I see that there are other people complaining about it.

@hasbro17
Copy link
Contributor

hasbro17 commented Mar 19, 2019

@nrvnrvn Thanks for reporting this. I was able to confirm this bug. Doesn't seem to be an upstream bug.
Side note: This doesn't relate directly to kubebuilder. It's the crd generator from the controller-tools repo that both kubebuilder and operator sdk are using.

I think this is probably due to the way we regenerate and only append the validation block to an existing CRD manifest.

// If the crd exists at i.Path, append the validation spec to its crd spec.
if _, err := os.Stat(i.Path); err == nil {
cb, err := ioutil.ReadFile(i.Path)
if err != nil {
return nil, err
}
if len(cb) > 0 {
dstCRD = &apiextv1beta1.CustomResourceDefinition{}
if err = yaml.Unmarshal(cb, dstCRD); err != nil {
return nil, err
}
dstCRD.Spec.Validation = val
}
}

I think we did this to avoid stomping out any user made changes to the CRD manifest like adding short names.

So the additionalPrinterColumns block is most likely generated correctly except we don't append that to the CRD manifest.

@estroz Thoughts? I think this should be a simple fix if we just append the AdditionalPrinterColumns block as well.

@hasbro17 hasbro17 added the kind/bug Categorizes issue or PR as related to a bug. label Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants