github.com/jmrodri/operator-sdk@v0.5.0/pkg/scaffold/doc.go (about)

     1  // Copyright 2018 The Operator-SDK Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package scaffold
    16  
    17  import (
    18  	"path/filepath"
    19  	"strings"
    20  
    21  	"github.com/operator-framework/operator-sdk/pkg/scaffold/input"
    22  )
    23  
    24  const DocFile = "doc.go"
    25  
    26  // Doc is the input needed to generate a pkg/apis/<group>/<version>/doc.go file
    27  type Doc struct {
    28  	input.Input
    29  
    30  	// Resource defines the inputs for the new doc file
    31  	Resource *Resource
    32  }
    33  
    34  func (s *Doc) GetInput() (input.Input, error) {
    35  	if s.Path == "" {
    36  		s.Path = filepath.Join(ApisDir,
    37  			strings.ToLower(s.Resource.Group),
    38  			strings.ToLower(s.Resource.Version),
    39  			DocFile)
    40  	}
    41  	s.IfExistsAction = input.Skip
    42  	s.TemplateBody = docTemplate
    43  	return s.Input, nil
    44  }
    45  
    46  const docTemplate = `// Package {{.Resource.Version}} contains API Schema definitions for the {{ .Resource.Group }} {{.Resource.Version}} API group
    47  // +k8s:deepcopy-gen=package,register
    48  // +groupName={{ .Resource.FullGroup }}
    49  package {{.Resource.Version}}
    50  `