sigs.k8s.io/kubebuilder/v3@v3.14.0/hack/docs/generate_samples.go (about) 1 /* 2 Copyright 2023 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 log "github.com/sirupsen/logrus" 21 22 componentconfig "sigs.k8s.io/kubebuilder/v3/hack/docs/internal/component-config-tutorial" 23 cronjob "sigs.k8s.io/kubebuilder/v3/hack/docs/internal/cronjob-tutorial" 24 ) 25 26 // Make sure executing `build_kb` to generate kb executable from the source code 27 const KubebuilderBinName = "/tmp/kubebuilder/bin/kubebuilder" 28 29 func main() { 30 log.SetFormatter(&log.TextFormatter{DisableTimestamp: true}) 31 log.Println("Generating documents...") 32 33 log.Println("Generating component-config tutorial...") 34 UpdateComponentConfigTutorial() 35 36 log.Println("Generating cronjob tutorial...") 37 UpdateCronjobTutorial() 38 // TODO: Generate multiversion-tutorial 39 } 40 41 func UpdateComponentConfigTutorial() { 42 binaryPath := KubebuilderBinName 43 samplePath := "docs/book/src/component-config-tutorial/testdata/project/" 44 45 sp := componentconfig.NewSample(binaryPath, samplePath) 46 47 sp.Prepare() 48 49 sp.GenerateSampleProject() 50 51 sp.UpdateTutorial() 52 53 sp.CodeGen() 54 } 55 56 func UpdateCronjobTutorial() { 57 binaryPath := KubebuilderBinName 58 samplePath := "docs/book/src/cronjob-tutorial/testdata/project/" 59 60 sp := cronjob.NewSample(binaryPath, samplePath) 61 62 sp.Prepare() 63 64 sp.GenerateSampleProject() 65 66 sp.UpdateTutorial() 67 }