|
| 1 | +/* |
| 2 | +Copyright 2024 The Kubernetes Authors. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package main |
| 18 | + |
| 19 | +import ( |
| 20 | + "flag" |
| 21 | + "fmt" |
| 22 | + "log" |
| 23 | + "os" |
| 24 | + "strings" |
| 25 | + |
| 26 | + "sigs.k8s.io/karpenter-provider-cluster-api/pkg/operator/options" |
| 27 | + coreoptions "sigs.k8s.io/karpenter/pkg/operator/options" |
| 28 | +) |
| 29 | + |
| 30 | +func main() { |
| 31 | + if len(os.Args) != 2 { |
| 32 | + log.Fatalf("Usage: go run main.go <path/to/settings.md>") |
| 33 | + } |
| 34 | + outputFileName := os.Args[1] |
| 35 | + |
| 36 | + title := "# Settings\n\n" |
| 37 | + comment := "[comment]: <> (the content below is generated from hack/docs/settings_gen/main.go)\n\n" |
| 38 | + description := "Karpenter exposes environment variables and CLI flags that allow you to configure controller behavior. The available settings are outlined below.\n\n" |
| 39 | + |
| 40 | + fs := &coreoptions.FlagSet{ |
| 41 | + FlagSet: flag.NewFlagSet("karpenter", flag.ContinueOnError), |
| 42 | + } |
| 43 | + (&coreoptions.Options{}).AddFlags(fs) |
| 44 | + (&options.Options{}).AddFlags(fs) |
| 45 | + |
| 46 | + envVarsTable := "| Environment Variable | CLI Flag | Description |\n" |
| 47 | + envVarsTable += "|--|--|--|\n" |
| 48 | + fs.VisitAll(func(f *flag.Flag) { |
| 49 | + if f.DefValue == "" { |
| 50 | + envVarsTable += fmt.Sprintf("| %s | %s | %s|\n", strings.ReplaceAll(strings.ToUpper(f.Name), "-", "_"), "\\-\\-"+f.Name, f.Usage) |
| 51 | + } else { |
| 52 | + envVarsTable += fmt.Sprintf("| %s | %s | %s (default = %s)|\n", strings.ReplaceAll(strings.ToUpper(f.Name), "-", "_"), "\\-\\-"+f.Name, f.Usage, f.DefValue) |
| 53 | + } |
| 54 | + }) |
| 55 | + |
| 56 | + log.Println("writing output to", outputFileName) |
| 57 | + err := os.WriteFile(outputFileName, []byte(title+comment+description+envVarsTable), 0644) |
| 58 | + if err != nil { |
| 59 | + log.Fatalf("failed to write file %s, %s", outputFileName, err) |
| 60 | + } |
| 61 | +} |
0 commit comments