Skip to content

Commit

Permalink
internal/pkg/scaffold/crd.go: CRD gets additionalPrinterColumns
Browse files Browse the repository at this point in the history
  • Loading branch information
estroz committed Apr 2, 2019
1 parent f9d902f commit aaf0cee
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions internal/pkg/scaffold/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,10 @@ func (s *CRD) CustomRender() ([]byte, error) {
if err != nil {
return nil, err
}
dstCRD = &apiextv1beta1.CustomResourceDefinition{}
if err = yaml.Unmarshal(b, dstCRD); err != nil {
srcCRD := &apiextv1beta1.CustomResourceDefinition{}
if err = yaml.Unmarshal(b, srcCRD); err != nil {
return nil, err
}
val := dstCRD.Spec.Validation.DeepCopy()

// If the crd exists at i.Path, append the validation spec to its crd spec.
if _, err := os.Stat(i.Path); err == nil {
Expand All @@ -132,8 +131,10 @@ func (s *CRD) CustomRender() ([]byte, error) {
if err = yaml.Unmarshal(cb, dstCRD); err != nil {
return nil, err
}
dstCRD.Spec.Validation = val
mergeCRDs(dstCRD, srcCRD)
}
} else {
dstCRD = srcCRD.DeepCopy()
}
// controller-tools does not set ListKind or Singular names.
dstCRD.Spec.Names = getCRDNamesForResource(s.Resource)
Expand Down Expand Up @@ -216,3 +217,8 @@ func addCRDVersions(crd *apiextv1beta1.CustomResourceDefinition) {
crd.Spec.Versions = crdVersions
}
}

func mergeCRDs(dst, src *apiextv1beta1.CustomResourceDefinition) {
dst.Spec.AdditionalPrinterColumns = src.Spec.AdditionalPrinterColumns
dst.Spec.Validation = src.Spec.Validation.DeepCopy()
}

0 comments on commit aaf0cee

Please sign in to comment.