Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Maintenance] Change MD content injection method #1256

Merged
merged 2 commits into from
Feb 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion docs/generated/actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -165,4 +168,5 @@ spec:
WaitForMemberReady: 30m0s
WaitForMemberUp: 30m0s

```
```
<!-- END(actionsModYaml) -->
5 changes: 4 additions & 1 deletion docs/generated/metrics/README.md
Original file line number Diff line number Diff line change
@@ -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 |
Expand Down Expand Up @@ -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) -->
23 changes: 3 additions & 20 deletions internal/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
11 changes: 0 additions & 11 deletions internal/actions.tmpl

This file was deleted.

98 changes: 98 additions & 0 deletions internal/md/sections.go
Original file line number Diff line number Diff line change
@@ -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 changes: 35 additions & 0 deletions internal/md/wrap.go
Original file line number Diff line number Diff line change
@@ -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)
}
23 changes: 2 additions & 21 deletions internal/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
}

Expand Down
5 changes: 0 additions & 5 deletions internal/metrics.tmpl

This file was deleted.