Skip to content

Commit

Permalink
Merge pull request #2066 from jack-evans/consistent-comments
Browse files Browse the repository at this point in the history
Make flux bootstrap and install comments consistent
  • Loading branch information
stefanprodan authored Nov 9, 2021
2 parents 83dc3e6 + 923a588 commit 50af0ba
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
4 changes: 0 additions & 4 deletions cmd/flux/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"fmt"
"os"
"path/filepath"
"strings"
"time"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -177,9 +176,6 @@ func installCmdRun(cmd *cobra.Command, args []string) error {
}

if installArgs.export {
fmt.Println("---")
fmt.Println("# Flux version:", installArgs.version)
fmt.Println("# Components:", strings.Join(components, ","))
fmt.Print(manifest.Content)
fmt.Println("---")
return nil
Expand Down
10 changes: 9 additions & 1 deletion pkg/manifestgen/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func Generate(options Options, manifestsBase string) (*manifestgen.Manifest, err

return &manifestgen.Manifest{
Path: path.Join(options.TargetPath, options.Namespace, options.ManifestFile),
Content: string(content),
Content: fmt.Sprintf("%s\n%s", GetGenWarning(options), string(content)),
}, nil
}

Expand Down Expand Up @@ -142,3 +142,11 @@ func ExistingVersion(version string) (bool, error) {
return false, fmt.Errorf("GitHub API returned an unexpected status code (%d)", res.StatusCode)
}
}

// GetGenWarning generates a consistent generation warning in the install and bootstrap case in the following format:
// # This manifest was generated by flux. DO NOT EDIT.
// # Flux version: v0.21.1
// # Components: source-controller,kustomize-controller,helm-controller,notification-controller,image-reflector-controller,image-automation-controller
func GetGenWarning(options Options) string {
return fmt.Sprintf("---\n%s\n# Flux Version: %s\n# Components: %s", manifestgen.GenWarning, options.Version, strings.Join(options.Components, ","))
}
5 changes: 5 additions & 0 deletions pkg/manifestgen/install/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,10 @@ func TestGenerate(t *testing.T) {
t.Errorf("toleration key '%s' not found", opts.TolerationKeys[0])
}

warning := GetGenWarning(opts)
if !strings.HasPrefix(output.Content, warning) {
t.Errorf("Generation warning '%s' not found", warning)
}

fmt.Println(output)
}
2 changes: 1 addition & 1 deletion pkg/manifestgen/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
securejoin "github.com/cyphar/filepath-securejoin"
)

const GenWarning = "# This manifest was generated by flux bootstrap. DO NOT EDIT."
const GenWarning = "# This manifest was generated by flux. DO NOT EDIT."

// Manifest holds the data of a multi-doc YAML
type Manifest struct {
Expand Down

0 comments on commit 50af0ba

Please sign in to comment.