@@ -22,7 +22,6 @@ package internal
2222
2323import (
2424 "bufio"
25- "bytes"
2625 "fmt"
2726 "go/ast"
2827 "go/token"
@@ -51,16 +50,15 @@ import (
5150 schedulerApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1"
5251 storageApi "github.com/arangodb/kube-arangodb/pkg/apis/storage/v1alpha"
5352 "github.com/arangodb/kube-arangodb/pkg/util"
53+ "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/helm"
5454)
5555
5656const (
5757 // title of docs/api/README.md page
5858 apiIndexPageTitle = "CRD reference"
5959)
6060
61- func (d DocDefinitions ) RenderMarkdown (t * testing.T , repositoryPath string ) []byte {
62- out := bytes .NewBuffer (nil )
63-
61+ func (d DocDefinitions ) RenderMarkdown (t * testing.T , out io.Writer , repositoryPath string ) {
6462 els := 0
6563
6664 for _ , el := range d {
@@ -189,8 +187,55 @@ func (d DocDefinitions) RenderMarkdown(t *testing.T, repositoryPath string) []by
189187 }
190188 }
191189 }
190+ }
191+
192+ func Test_GenerateSecondaryAPIDocs (t * testing.T ) {
193+ root := os .Getenv ("ROOT" )
194+ require .NotEmpty (t , root )
195+
196+ fset := token .NewFileSet ()
197+
198+ fields := parseSourceFiles (t , root , fset , path .Join (root , "pkg/util/k8sutil/helm" ))
192199
193- return out .Bytes ()
200+ out , err := os .OpenFile (path .Join (root , "docs/platform.install.md" ), os .O_WRONLY | os .O_CREATE | os .O_TRUNC , 0644 )
201+ require .NoError (t , err )
202+
203+ defer func () {
204+ require .NoError (t , out .Close ())
205+ }()
206+
207+ writeFrontMatter (t , out , map [string ]string {
208+ "layout" : "page" ,
209+ "title" : "Platform Installation File Schema" ,
210+ "parent" : "ArangoDBPlatform" ,
211+ })
212+ writef (t , out , "# Installation Definition\n \n " )
213+ writef (t , out , "## Example\n \n " )
214+ writef (t , out , "```yaml\n " )
215+ writef (t , out , `packages:
216+ nginx: # OCI
217+ chart: "oci://ghcr.io/nginx/charts/nginx-ingress:2.3.1"
218+ version: 2.3.1
219+ prometheus: # Helm Index
220+ chart: "index://prometheus-community.github.io/helm-charts"
221+ version: 1.3.1
222+ alertmanager: # Remote Chart
223+ chart: "https://github.com/prometheus-community/helm-charts/releases/download/alertmanager-0.1.0/alertmanager-0.1.0.tgz"
224+ version: "0.1.0"
225+ local: # Local File
226+ chart: "file:///tmp/local-0.1.0.tgz"
227+ version: "0.1.0"
228+ inline: # Inline
229+ chart: "<base64 string>"
230+ version: "0.2.5"
231+ platform: # Platform LicenseManager
232+ version: v3.0.11
233+ ` )
234+ writef (t , out , "```\n \n " )
235+
236+ generateDocsOut (t , "Package" , map [string ]interface {}{
237+ "Package" : helm.Package {},
238+ }, fields , fset , out )
194239}
195240
196241func Test_GenerateAPIDocs (t * testing.T ) {
@@ -503,59 +548,59 @@ func prepareGitHubTreePath(t *testing.T, root string) string {
503548 return fmt .Sprintf ("https://github.com/arangodb/kube-arangodb/blob/%s" , ref )
504549}
505550
506- func generateDocs (t * testing.T , objects map [ string ] map [string ]interface {}, fields map [string ]* ast.Field , fs * token.FileSet ) map [ string ] string {
551+ func generateDocsOut (t * testing.T , objectName string , sections map [string ]interface {}, fields map [string ]* ast.Field , fs * token.FileSet , out io. Writer ) {
507552 root := os .Getenv ("ROOT" )
508553 require .NotEmpty (t , root )
509554
510- outPaths := make (map [string ]string )
511-
512555 repositoryPath := prepareGitHubTreePath (t , root )
513556
514- for objectName , sections := range objects {
515- t .Run (objectName , func (t * testing.T ) {
516- renderSections := map [string ][]byte {}
517- for section , fieldInstance := range sections {
518- t .Run (section , func (t * testing.T ) {
557+ t .Run (objectName , func (t * testing.T ) {
558+ for _ , section := range util .SortKeys (sections ) {
559+ writef (t , out , "## %s\n \n " , util .BoolSwitch (section == "" , "Object" , section ))
519560
520- sectionParsed := iterateOverObject (t , fields , "" , goStrings .ToLower (section ), reflect .TypeOf (fieldInstance ), "" )
561+ t .Run (section , func (t * testing.T ) {
562+ fieldInstance := sections [section ]
521563
522- defs := make (DocDefinitions , 0 , len (sectionParsed ))
523- for _ , el := range sectionParsed {
524- defs = append (defs , parseDocDefinition (t , root , cleanPrefixPath (el .K .path ), el .K .typ , el .K , el .V , fs ))
525- }
526- defs .Sort ()
564+ sectionParsed := iterateOverObject (t , fields , "" , goStrings .ToLower (section ), reflect .TypeOf (fieldInstance ), "" )
527565
528- renderSections [section ] = defs .RenderMarkdown (t , repositoryPath )
529- })
530- }
566+ defs := make (DocDefinitions , 0 , len (sectionParsed ))
567+ for _ , el := range sectionParsed {
568+ defs = append (defs , parseDocDefinition (t , root , cleanPrefixPath (el .K .path ), el .K .typ , el .K , el .V , fs ))
569+ }
570+ defs .Sort ()
571+
572+ defs .RenderMarkdown (t , out , repositoryPath )
573+ })
574+ }
575+ })
576+ }
531577
532- fileName := fmt .Sprintf ("%s.md" , objectName )
533- outPaths [objectName ] = fileName
578+ func generateDocs (t * testing.T , objects map [string ]map [string ]interface {}, fields map [string ]* ast.Field , fs * token.FileSet ) {
579+ root := os .Getenv ("ROOT" )
580+ require .NotEmpty (t , root )
581+
582+ for objectName , sections := range objects {
583+ t .Run (objectName , func (t * testing.T ) {
534584 outPath := path .Join (root , "docs/api" , fmt .Sprintf ("%s.md" , objectName ))
535- out , err := os .OpenFile (outPath , os .O_CREATE | os .O_TRUNC | os .O_WRONLY , 0644 )
585+ out , err := os .OpenFile (outPath , os .O_TRUNC | os .O_WRONLY | os .O_CREATE , 0644 )
536586 require .NoError (t , err )
537587
538588 defer func () {
539589 require .NoError (t , out .Close ())
540590 }()
541591
542592 objName := goStrings .ReplaceAll (objectName , "." , " " )
593+
543594 writeFrontMatter (t , out , map [string ]string {
544595 "layout" : "page" ,
545596 "title" : objName ,
546597 "parent" : apiIndexPageTitle ,
547598 })
548599 writef (t , out , "# API Reference for %s\n \n " , objName )
549600
550- util .IterateSorted (renderSections , func (name string , section []byte ) {
551- writef (t , out , "## %s\n \n " , util .BoolSwitch (name == "" , "Object" , name ))
552-
553- _ , err = out .Write (section )
554- require .NoError (t , err )
555- })
601+ generateDocsOut (t , objectName , sections , fields , fs , out )
556602 })
557603 }
558- return outPaths
559604}
560605
561606func write (t * testing.T , out io.Writer , format string ) {
0 commit comments