mirror of
https://github.com/arangodb/kube-arangodb.git
synced 2024-12-14 11:57:37 +00:00
[Maintenance] Change MD content injection method (#1256)
This commit is contained in:
parent
2fcace5caf
commit
b9aed8e6fa
9 changed files with 148 additions and 59 deletions
|
@ -17,6 +17,7 @@
|
|||
- (Bugfix) Fix invalid Timeout calculation in case of ActionList
|
||||
- (Feature) Optional JSON logger format
|
||||
- (Improvement) Change Operator default ReplicasCount to 1
|
||||
- (Maintenance) Change MD content injection method
|
||||
|
||||
## [1.2.24](https://github.com/arangodb/kube-arangodb/tree/1.2.24) (2023-01-25)
|
||||
- (Bugfix) Fix deployment creation on ARM64
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
## List
|
||||
|
||||
<!-- START(actionsTable) -->
|
||||
| Action | Internal | Timeout | Optional | Edition | Description |
|
||||
|:----------------------------------:|:--------:|:-------:|:--------:|:----------------------:|:------------------------------------------------------------------------------------------------------------------:|
|
||||
| AddMember | no | 10m0s | no | Community & Enterprise | Adds new member to the Member list |
|
||||
|
@ -81,9 +82,11 @@
|
|||
| WaitForMemberReady | no | 30m0s | no | Community & Enterprise | Wait for member Ready condition |
|
||||
| WaitForMemberUp | no | 30m0s | no | Community & Enterprise | Wait for member to be responsive |
|
||||
|
||||
<!-- END(actionsTable) -->
|
||||
|
||||
## ArangoDeployment spec
|
||||
|
||||
<!-- START(actionsModYaml) -->
|
||||
```yaml
|
||||
spec:
|
||||
timeouts:
|
||||
|
@ -165,4 +168,5 @@ spec:
|
|||
WaitForMemberReady: 30m0s
|
||||
WaitForMemberUp: 30m0s
|
||||
|
||||
```
|
||||
```
|
||||
<!-- END(actionsModYaml) -->
|
|
@ -1,7 +1,8 @@
|
|||
# ArangoDB Operator Metrics
|
||||
|
||||
## List
|
||||
## List of the Operator metrics
|
||||
|
||||
<!-- START(metricsTable) -->
|
||||
| Name | Namespace | Group | Type | Description |
|
||||
|:-------------------------------------------------------------------------------------------------------------------------------------:|:-----------------:|:-----------------:|:-------:|:--------------------------------------------------------------------------------------|
|
||||
| [arangodb_operator_agency_errors](./arangodb_operator_agency_errors.md) | arangodb_operator | agency | Counter | Current count of agency cache fetch errors |
|
||||
|
@ -30,3 +31,5 @@
|
|||
| [arangodb_operator_resources_arangodeployment_status_restores](./arangodb_operator_resources_arangodeployment_status_restores.md) | arangodb_operator | resources | Counter | Counter for deployment status restored |
|
||||
| [arangodb_operator_resources_arangodeployment_uptodate](./arangodb_operator_resources_arangodeployment_uptodate.md) | arangodb_operator | resources | Gauge | Defines if ArangoDeployment is uptodate |
|
||||
| [arangodb_operator_resources_arangodeployment_validation_errors](./arangodb_operator_resources_arangodeployment_validation_errors.md) | arangodb_operator | resources | Counter | Counter for deployment validation errors |
|
||||
|
||||
<!-- END(metricsTable) -->
|
|
@ -40,9 +40,6 @@ import (
|
|||
//go:embed actions.yaml
|
||||
var actions []byte
|
||||
|
||||
//go:embed actions.tmpl
|
||||
var actionsMD []byte
|
||||
|
||||
//go:embed actions.go.tmpl
|
||||
var actionsGoTemplate []byte
|
||||
|
||||
|
@ -300,16 +297,6 @@ func RenderActions(root string) error {
|
|||
{
|
||||
actions := path.Join(root, "docs", "generated", "actions.md")
|
||||
|
||||
out, err := os.OpenFile(actions, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
i, err := template.New("actions").Parse(string(actionsMD))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
action := md.NewColumn("Action", md.ColumnCenterAlign)
|
||||
timeout := md.NewColumn("Timeout", md.ColumnCenterAlign)
|
||||
description := md.NewColumn("Description", md.ColumnCenterAlign)
|
||||
|
@ -379,16 +366,12 @@ func RenderActions(root string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if err := i.Execute(out, map[string]interface{}{
|
||||
"table": t.Render(),
|
||||
"example": string(d),
|
||||
if err := md.ReplaceSectionsInFile(actions, map[string]string{
|
||||
"actionsTable": md.WrapWithNewLines(t.Render()),
|
||||
"actionsModYaml": md.WrapWithNewLines(md.WrapWithYAMLSegment(string(d))),
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := out.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
# ArangoDB Operator Metrics
|
||||
|
||||
## List
|
||||
|
||||
{{ .table }}
|
||||
|
||||
## ArangoDeployment spec
|
||||
|
||||
```yaml
|
||||
{{ .example }}
|
||||
```
|
98
internal/md/sections.go
Normal file
98
internal/md/sections.go
Normal file
|
@ -0,0 +1,98 @@
|
|||
//
|
||||
// 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 md
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/arangodb/kube-arangodb/pkg/util/errors"
|
||||
)
|
||||
|
||||
func ReplaceSectionsInFile(path string, sections map[string]string) error {
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
res, err := ReplaceSections(string(data), sections)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return os.WriteFile(path, []byte(res), 0644)
|
||||
}
|
||||
|
||||
func ReplaceSections(in string, sections map[string]string) (string, error) {
|
||||
for k, v := range sections {
|
||||
if n, err := ReplaceSection(in, v, k); err != nil {
|
||||
return "", err
|
||||
} else {
|
||||
in = n
|
||||
}
|
||||
}
|
||||
|
||||
return in, nil
|
||||
}
|
||||
|
||||
func ReplaceSection(in, replace, section string) (string, error) {
|
||||
start, end := fmt.Sprintf("<!-- START(%s) -->", section), fmt.Sprintf("<!-- END(%s) -->", section)
|
||||
|
||||
b := bytes.NewBuffer(nil)
|
||||
|
||||
for len(in) > 0 {
|
||||
startID := strings.Index(in, start)
|
||||
if startID == -1 {
|
||||
b.WriteString(in)
|
||||
in = ""
|
||||
continue
|
||||
}
|
||||
|
||||
b.WriteString(in[0:startID])
|
||||
|
||||
in = moveString(in, startID+len(start))
|
||||
|
||||
b.WriteString(start)
|
||||
|
||||
b.WriteString(replace)
|
||||
|
||||
endID := strings.Index(in, end)
|
||||
if endID == -1 {
|
||||
return "", errors.Newf("END sections is missing")
|
||||
}
|
||||
|
||||
b.WriteString(end)
|
||||
|
||||
in = moveString(in, endID+len(end))
|
||||
}
|
||||
|
||||
return b.String(), nil
|
||||
}
|
||||
|
||||
func moveString(in string, offset int) string {
|
||||
if offset >= len(in) {
|
||||
return ""
|
||||
}
|
||||
|
||||
return in[offset:]
|
||||
}
|
35
internal/md/wrap.go
Normal file
35
internal/md/wrap.go
Normal file
|
@ -0,0 +1,35 @@
|
|||
//
|
||||
// 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 md
|
||||
|
||||
import "fmt"
|
||||
|
||||
func WrapWithNewLines(in string) string {
|
||||
return fmt.Sprintf("\n%s\n", in)
|
||||
}
|
||||
|
||||
func WrapWithYAMLSegment(in string) string {
|
||||
return WrapWithSegment(in, "yaml")
|
||||
}
|
||||
|
||||
func WrapWithSegment(in, segment string) string {
|
||||
return fmt.Sprintf("```%s\n%s\n```", segment, in)
|
||||
}
|
|
@ -38,9 +38,6 @@ var metricsGoTemplate []byte
|
|||
//go:embed metrics.item.go.tmpl
|
||||
var metricsItemGoTemplate []byte
|
||||
|
||||
//go:embed metrics.tmpl
|
||||
var metricsTemplate []byte
|
||||
|
||||
//go:embed metrics.item.tmpl
|
||||
var metricItemTemplate []byte
|
||||
|
||||
|
@ -255,28 +252,12 @@ func generateMetricsREADME(root string, in MetricsDoc) error {
|
|||
}
|
||||
}
|
||||
|
||||
table := t.Render()
|
||||
|
||||
q, err := template.New("metrics").Parse(string(metricsTemplate))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
out, err := os.OpenFile(path.Join(root, "README.md"), os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := q.Execute(out, map[string]interface{}{
|
||||
"table": table,
|
||||
if err := md.ReplaceSectionsInFile(path.Join(root, "README.md"), map[string]string{
|
||||
"metricsTable": md.WrapWithNewLines(t.Render()),
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := out.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
# ArangoDB Operator Metrics
|
||||
|
||||
## List
|
||||
|
||||
{{ .table }}
|
Loading…
Reference in a new issue