2023-02-24 11:16:35 +00:00
|
|
|
//
|
|
|
|
// DISCLAIMER
|
|
|
|
//
|
2024-01-08 15:58:01 +00:00
|
|
|
// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany
|
2023-02-24 11:16:35 +00:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
//
|
|
|
|
// Copyright holder is ArangoDB GmbH, Cologne, Germany
|
|
|
|
//
|
|
|
|
|
|
|
|
package internal
|
|
|
|
|
|
|
|
import (
|
2024-05-21 09:55:06 +00:00
|
|
|
"bytes"
|
2023-07-24 15:10:59 +00:00
|
|
|
"fmt"
|
2023-02-24 11:16:35 +00:00
|
|
|
"os"
|
|
|
|
"path"
|
2023-10-19 07:14:14 +00:00
|
|
|
"path/filepath"
|
2023-07-24 15:10:59 +00:00
|
|
|
"sort"
|
|
|
|
"strings"
|
2023-02-24 11:16:35 +00:00
|
|
|
|
2024-05-21 09:55:06 +00:00
|
|
|
"github.com/spf13/cobra"
|
2023-02-24 11:16:35 +00:00
|
|
|
"gopkg.in/yaml.v3"
|
|
|
|
|
2023-07-24 15:10:59 +00:00
|
|
|
"github.com/arangodb/go-driver"
|
|
|
|
|
2024-05-21 09:55:06 +00:00
|
|
|
"github.com/arangodb/kube-arangodb/cmd"
|
2023-02-24 11:16:35 +00:00
|
|
|
"github.com/arangodb/kube-arangodb/internal/md"
|
2024-01-08 15:58:01 +00:00
|
|
|
"github.com/arangodb/kube-arangodb/pkg/deployment/features"
|
2023-02-24 11:16:35 +00:00
|
|
|
"github.com/arangodb/kube-arangodb/pkg/util"
|
|
|
|
)
|
|
|
|
|
|
|
|
type PlatformsDoc struct {
|
|
|
|
Platforms Platforms `json:"platforms,omitempty" yaml:"platforms,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type Platforms []Platform
|
|
|
|
|
|
|
|
type Platform struct {
|
|
|
|
Name string `json:"name,omitempty" yaml:"name,omitempty"`
|
|
|
|
Versions []PlatformVersion `json:"versions,omitempty" yaml:"versions,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type PlatformVersion struct {
|
|
|
|
KubernetesVersion *string `json:"kubernetesVersion,omitempty" yaml:"kubernetesVersion,omitempty"`
|
|
|
|
ArangoDBVersion *string `json:"arangoDBVersion,omitempty" yaml:"arangoDBVersion,omitempty"`
|
|
|
|
State *string `json:"state,omitempty" yaml:"state,omitempty"`
|
|
|
|
Remarks *string `json:"remarks,omitempty" yaml:"remarks,omitempty"`
|
|
|
|
ProviderRemarks *string `json:"providerRemarks,omitempty" yaml:"providerRemarks,omitempty"`
|
|
|
|
}
|
|
|
|
|
2023-07-24 15:10:59 +00:00
|
|
|
type FeaturesDoc struct {
|
|
|
|
Features Features `json:"features,omitempty" yaml:"features,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type Features []Feature
|
|
|
|
|
|
|
|
type Feature struct {
|
|
|
|
Name string `json:"name,omitempty" yaml:"name,omitempty"`
|
|
|
|
Releases FeatureReleases `json:"releases,omitempty" yaml:"releases,omitempty"`
|
|
|
|
|
|
|
|
FeatureRelease `json:",inline" yaml:",inline"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type FeatureReleases []FeatureRelease
|
|
|
|
|
|
|
|
type FeatureRelease struct {
|
|
|
|
Doc *string `json:"doc,omitempty" yaml:"doc,omitempty"`
|
|
|
|
|
|
|
|
OperatorVersion *string `json:"operatorVersion,omitempty" yaml:"operatorVersion,omitempty"`
|
|
|
|
ArangoDBVersion *string `json:"arangoDBVersion,omitempty" yaml:"arangoDBVersion,omitempty"`
|
|
|
|
|
|
|
|
OperatorEdition *string `json:"operatorEditions,omitempty" yaml:"operatorEditions,omitempty"`
|
|
|
|
ArangoDBEdition *string `json:"arangoDBEditions,omitempty" yaml:"arangoDBEditions,omitempty"`
|
|
|
|
|
|
|
|
State *string `json:"state,omitempty" yaml:"state,omitempty"`
|
|
|
|
Flag *string `json:"flag,omitempty" yaml:"flag,omitempty"`
|
|
|
|
Remarks *string `json:"remarks,omitempty" yaml:"remarks,omitempty"`
|
|
|
|
|
|
|
|
Enabled *bool `json:"enabled,omitempty" yaml:"enabled,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type LimitsDoc struct {
|
|
|
|
Limits Limits `json:"limits,omitempty" yaml:"limits,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type Limits []Limit
|
|
|
|
|
|
|
|
type Limit struct {
|
|
|
|
Name string `json:"name" yaml:"name"`
|
|
|
|
Description string `json:"description" yaml:"description"`
|
|
|
|
Community *string `json:"community,omitempty" yaml:"community,omitempty"`
|
|
|
|
Enterprise *string `json:"enterprise,omitempty" yaml:"enterprise,omitempty"`
|
|
|
|
}
|
|
|
|
|
2023-02-24 11:16:35 +00:00
|
|
|
func GenerateReadme(root string) error {
|
|
|
|
readmeSections := map[string]string{}
|
|
|
|
|
2023-07-24 15:10:59 +00:00
|
|
|
if section, err := GenerateReadmePlatforms(root); err != nil {
|
|
|
|
return err
|
|
|
|
} else {
|
|
|
|
readmeSections["kubernetesVersionsTable"] = section
|
|
|
|
}
|
2023-02-24 11:16:35 +00:00
|
|
|
|
2023-10-19 07:14:14 +00:00
|
|
|
const basePath = ""
|
|
|
|
if section, err := GenerateReadmeFeatures(root, basePath, true); err != nil {
|
2023-07-24 15:10:59 +00:00
|
|
|
return err
|
|
|
|
} else {
|
|
|
|
readmeSections["featuresEnterpriseTable"] = section
|
|
|
|
}
|
2023-02-24 11:16:35 +00:00
|
|
|
|
2023-10-19 07:14:14 +00:00
|
|
|
if section, err := GenerateReadmeFeatures(root, basePath, false); err != nil {
|
2023-07-24 15:10:59 +00:00
|
|
|
return err
|
|
|
|
} else {
|
|
|
|
readmeSections["featuresCommunityTable"] = section
|
|
|
|
}
|
2023-02-24 11:16:35 +00:00
|
|
|
|
2023-07-24 15:10:59 +00:00
|
|
|
if section, err := GenerateReadmeLimits(root); err != nil {
|
|
|
|
return err
|
|
|
|
} else {
|
|
|
|
readmeSections["limits"] = section
|
2023-02-24 11:16:35 +00:00
|
|
|
}
|
|
|
|
|
2024-05-21 09:55:06 +00:00
|
|
|
if section, err := GenerateHelp(cmd.Command()); err != nil {
|
|
|
|
return err
|
|
|
|
} else {
|
|
|
|
readmeSections["operatorArguments"] = section
|
|
|
|
}
|
|
|
|
|
2023-02-24 11:16:35 +00:00
|
|
|
if err := md.ReplaceSectionsInFile(path.Join(root, "README.md"), readmeSections); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2023-07-24 15:10:59 +00:00
|
|
|
|
2024-08-28 07:48:59 +00:00
|
|
|
func GenerateHelp(cmd *cobra.Command, args ...string) (string, error) {
|
2024-05-21 09:55:06 +00:00
|
|
|
var lines []string
|
|
|
|
|
|
|
|
lines = append(lines, "```", "Flags:")
|
|
|
|
|
2024-08-28 07:48:59 +00:00
|
|
|
help, err := GenerateHelpRaw(cmd, args...)
|
|
|
|
if err != nil {
|
2024-05-21 09:55:06 +00:00
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, line := range strings.Split(help, "\n") {
|
|
|
|
if strings.HasPrefix(line, " --") {
|
|
|
|
lines = append(lines, line)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
lines = append(lines, "```")
|
|
|
|
|
|
|
|
return md.WrapWithNewLines(md.WrapWithNewLines(strings.Join(lines, "\n"))), nil
|
|
|
|
}
|
|
|
|
|
2024-08-28 07:48:59 +00:00
|
|
|
func GenerateHelpQuoted(cmd *cobra.Command, args ...string) (string, error) {
|
|
|
|
h, err := GenerateHelpRaw(cmd, args...)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
return fmt.Sprintf("```\n%s```\n", h), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func GenerateHelpRaw(cmd *cobra.Command, args ...string) (string, error) {
|
|
|
|
buff := bytes.NewBuffer(nil)
|
|
|
|
|
|
|
|
cmd.SetOut(buff)
|
|
|
|
|
|
|
|
cmd.SetArgs(append(args, "--help"))
|
|
|
|
|
|
|
|
if err := cmd.Execute(); err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
return buff.String(), nil
|
|
|
|
}
|
|
|
|
|
2023-10-19 07:14:14 +00:00
|
|
|
func GenerateReadmeFeatures(root, basePath string, eeOnly bool) (string, error) {
|
2023-07-24 15:10:59 +00:00
|
|
|
feature := md.NewColumn("Feature", md.ColumnLeftAlign)
|
|
|
|
introduced := md.NewColumn("Introduced", md.ColumnLeftAlign)
|
|
|
|
oVersion := md.NewColumn("Operator Version", md.ColumnLeftAlign)
|
|
|
|
aVersion := md.NewColumn("ArangoDB Version", md.ColumnLeftAlign)
|
|
|
|
aEdition := md.NewColumn("ArangoDB Edition", md.ColumnLeftAlign)
|
|
|
|
state := md.NewColumn("State", md.ColumnLeftAlign)
|
|
|
|
enabled := md.NewColumn("Enabled", md.ColumnLeftAlign)
|
|
|
|
flag := md.NewColumn("Flag", md.ColumnLeftAlign)
|
|
|
|
remarks := md.NewColumn("Remarks", md.ColumnLeftAlign)
|
|
|
|
t := md.NewTable(
|
|
|
|
feature,
|
|
|
|
oVersion,
|
|
|
|
introduced,
|
|
|
|
aVersion,
|
|
|
|
aEdition,
|
|
|
|
state,
|
|
|
|
enabled,
|
|
|
|
flag,
|
|
|
|
remarks,
|
|
|
|
)
|
|
|
|
|
|
|
|
var d FeaturesDoc
|
|
|
|
|
|
|
|
data, err := os.ReadFile(path.Join(root, "internal", "features.yaml"))
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := yaml.Unmarshal(data, &d); err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sort list
|
|
|
|
|
|
|
|
sort.Slice(d.Features, func(i, j int) bool {
|
|
|
|
{
|
|
|
|
av := util.First(util.LastFromList(d.Features[i].Releases).OperatorVersion, d.Features[i].OperatorVersion)
|
|
|
|
bv := util.First(util.LastFromList(d.Features[j].Releases).OperatorVersion, d.Features[j].OperatorVersion)
|
|
|
|
|
|
|
|
a := driver.Version(util.TypeOrDefault[string](av, "1.0.0"))
|
|
|
|
b := driver.Version(util.TypeOrDefault[string](bv, "1.0.0"))
|
|
|
|
|
|
|
|
if c := a.CompareTo(b); c != 0 {
|
|
|
|
return c > 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
a := driver.Version(util.TypeOrDefault[string](d.Features[i].Releases[0].OperatorVersion, "1.0.0"))
|
|
|
|
b := driver.Version(util.TypeOrDefault[string](d.Features[j].Releases[0].OperatorVersion, "1.0.0"))
|
|
|
|
|
|
|
|
if c := a.CompareTo(b); c != 0 {
|
|
|
|
return c > 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return d.Features[i].Name < d.Features[j].Name
|
|
|
|
})
|
|
|
|
|
|
|
|
for _, f := range d.Features {
|
|
|
|
r := f.Releases[len(f.Releases)-1]
|
|
|
|
|
|
|
|
if community := strings.Contains(util.TypeOrDefault(util.First(r.OperatorEdition, f.OperatorEdition), "Community, Enterprise"), "Community"); community == eeOnly {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
n := f.Name
|
|
|
|
|
|
|
|
if v := util.First(r.Doc, f.Doc); v != nil {
|
2023-10-19 07:14:14 +00:00
|
|
|
p, err := filepath.Rel(basePath, *v)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
n = fmt.Sprintf("[%s](%s)", n, p)
|
2023-07-24 15:10:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := t.AddRow(map[md.Column]string{
|
|
|
|
feature: n,
|
|
|
|
oVersion: util.TypeOrDefault[string](util.First(r.OperatorVersion, f.OperatorVersion), "ANY"),
|
|
|
|
introduced: util.TypeOrDefault[string](f.Releases[0].OperatorVersion, "ANY"),
|
2024-01-08 15:58:01 +00:00
|
|
|
aVersion: util.TypeOrDefault[string](util.First(r.ArangoDBVersion, f.ArangoDBVersion), fmt.Sprintf(">= %s", features.MinSupportedArangoDBVersion)),
|
2023-07-24 15:10:59 +00:00
|
|
|
aEdition: util.TypeOrDefault[string](util.First(r.ArangoDBEdition, f.ArangoDBEdition), "Community, Enterprise"),
|
|
|
|
aEdition: util.TypeOrDefault[string](util.First(r.ArangoDBEdition, f.ArangoDBEdition), "Community, Enterprise"),
|
|
|
|
state: util.TypeOrDefault[string](util.First(r.State, f.State), "Alpha"),
|
|
|
|
enabled: util.BoolSwitch[string](util.TypeOrDefault[bool](util.First(r.Enabled, f.Enabled), true), "True", "False"),
|
|
|
|
flag: util.TypeOrDefault[string](util.First(r.Flag, f.Flag), "N/A"),
|
|
|
|
remarks: util.TypeOrDefault[string](util.First(r.Remarks, f.Remarks), "N/A"),
|
|
|
|
}); err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return md.WrapWithNewLines(t.Render()), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func GenerateReadmeLimits(root string) (string, error) {
|
|
|
|
limit := md.NewColumn("Limit", md.ColumnLeftAlign)
|
|
|
|
description := md.NewColumn("Description", md.ColumnLeftAlign)
|
|
|
|
community := md.NewColumn("Community", md.ColumnLeftAlign)
|
|
|
|
enterprise := md.NewColumn("Enterprise", md.ColumnLeftAlign)
|
|
|
|
t := md.NewTable(
|
|
|
|
limit,
|
|
|
|
description,
|
|
|
|
community,
|
|
|
|
enterprise,
|
|
|
|
)
|
|
|
|
|
|
|
|
var d LimitsDoc
|
|
|
|
|
|
|
|
data, err := os.ReadFile(path.Join(root, "internal", "limits.yaml"))
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := yaml.Unmarshal(data, &d); err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, l := range d.Limits {
|
|
|
|
if err := t.AddRow(map[md.Column]string{
|
|
|
|
limit: l.Name,
|
|
|
|
description: l.Description,
|
|
|
|
community: util.TypeOrDefault[string](l.Community, "N/A"),
|
|
|
|
enterprise: util.TypeOrDefault[string](l.Enterprise, "N/A"),
|
|
|
|
}); err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return md.WrapWithNewLines(t.Render()), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func GenerateReadmePlatforms(root string) (string, error) {
|
|
|
|
platform := md.NewColumn("Platform", md.ColumnLeftAlign)
|
|
|
|
kVersion := md.NewColumn("Kubernetes Version", md.ColumnLeftAlign)
|
|
|
|
aVersion := md.NewColumn("ArangoDB Version", md.ColumnLeftAlign)
|
|
|
|
state := md.NewColumn("State", md.ColumnLeftAlign)
|
|
|
|
remarks := md.NewColumn("Remarks", md.ColumnLeftAlign)
|
|
|
|
pRemarks := md.NewColumn("Provider Remarks", md.ColumnLeftAlign)
|
|
|
|
t := md.NewTable(
|
|
|
|
platform,
|
2024-10-11 12:10:55 +00:00
|
|
|
state,
|
2023-07-24 15:10:59 +00:00
|
|
|
kVersion,
|
|
|
|
aVersion,
|
|
|
|
remarks,
|
|
|
|
pRemarks,
|
|
|
|
)
|
|
|
|
|
|
|
|
var d PlatformsDoc
|
|
|
|
|
|
|
|
data, err := os.ReadFile(path.Join(root, "internal", "platforms.yaml"))
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := yaml.Unmarshal(data, &d); err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, p := range d.Platforms {
|
2024-10-11 12:10:55 +00:00
|
|
|
for id, v := range p.Versions {
|
|
|
|
n := ""
|
|
|
|
if id == 0 {
|
|
|
|
n = p.Name
|
|
|
|
}
|
2023-07-24 15:10:59 +00:00
|
|
|
if err := t.AddRow(map[md.Column]string{
|
2024-10-11 12:10:55 +00:00
|
|
|
platform: n,
|
2023-07-24 15:10:59 +00:00
|
|
|
kVersion: util.TypeOrDefault[string](v.KubernetesVersion, ""),
|
|
|
|
aVersion: util.TypeOrDefault[string](v.ArangoDBVersion, ""),
|
|
|
|
state: util.TypeOrDefault[string](v.State, ""),
|
|
|
|
remarks: util.TypeOrDefault[string](v.Remarks, ""),
|
|
|
|
pRemarks: util.TypeOrDefault[string](v.ProviderRemarks, ""),
|
|
|
|
}); err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return md.WrapWithNewLines(t.Render()), nil
|
|
|
|
}
|