1
0
Fork 0
mirror of https://github.com/arangodb/kube-arangodb.git synced 2024-12-14 11:57:37 +00:00
kube-arangodb/internal
2023-05-24 15:12:27 +02:00
..
md [Maintenance] Change MD content injection method (#1256) 2023-02-24 09:29:35 +01:00
actions.go [Maintenance] Change MD content injection method (#1256) 2023-02-24 09:29:35 +01:00
actions.go.tmpl [Feature] Optional Action (#1245) 2023-02-20 12:20:01 +01:00
actions.register.go.tmpl [Maintenance] Fix generated license dates (#1244) 2023-02-20 06:01:54 +01:00
actions.register.test.go.tmpl [Feature] Optional Action (#1245) 2023-02-20 12:20:01 +01:00
actions.yaml GT-405 Automatically fix out of sync shards with broken MerkleTree (#1296) 2023-04-25 17:19:13 +02:00
actions_test.go [Bugfix] Fix action timeouts (#1112) 2022-09-19 17:24:54 +02:00
metrics.go [Maintenance] Generate README Platforms (#1257) 2023-02-24 12:16:35 +01:00
metrics.go.tmpl [Maintenance] Fix generated license dates (#1244) 2023-02-20 06:01:54 +01:00
metrics.item.go.tmpl [Maintenance] Fix generated license dates (#1244) 2023-02-20 06:01:54 +01:00
metrics.item.tmpl [Documentation] Refactor metrics (Part 1) (#1019) 2022-06-27 08:02:21 +02:00
metrics.yaml [Feature] Add Reason in OOM Metric (#1308) 2023-05-08 12:18:45 +02:00
metrics_test.go [Documentation] Refactor metrics (Part 1) (#1019) 2022-06-27 08:02:21 +02:00
platforms.yaml [Maintenance] Generate README Platforms (#1257) 2023-02-24 12:16:35 +01:00
readme.go [Feature] Generics for type handling (#1313) 2023-05-24 15:12:27 +02:00
readme_test.go [Maintenance] Generate README Platforms (#1257) 2023-02-24 12:16:35 +01:00
timezones.go [Update] Update Go to 1.19 (#1216) 2022-12-22 10:49:51 +01:00
timezones.go.tmpl [Feature] Immutable spec (#1089) 2022-08-25 13:44:28 +02:00
timezones_test.go [Bugfix] Fix action timeouts (#1112) 2022-09-19 17:24:54 +02:00

//
// DISCLAIMER
//
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
//
// 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 (
	"os"
	"path"

	"gopkg.in/yaml.v3"

	"github.com/arangodb/kube-arangodb/internal/md"
	"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"`
}

func GenerateReadme(root string) error {
	readmeSections := map[string]string{}

	{
		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,
			kVersion,
			aVersion,
			state,
			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 {
			for _, v := range p.Versions {
				if err := t.AddRow(map[md.Column]string{
					platform: p.Name,
					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
				}
			}
		}

		readmeSections["metricsTable"] = md.WrapWithNewLines(t.Render())
	}

	if err := md.ReplaceSectionsInFile(path.Join(root, "README.md"), readmeSections); err != nil {
		return err
	}

	return nil
}