sigs.k8s.io/kubebuilder/v3@v3.14.0/pkg/plugins/optional/grafana/v1alpha/scaffolds/init.go (about) 1 /* 2 Copyright 2022 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 scaffolds 18 19 import ( 20 log "github.com/sirupsen/logrus" 21 22 "sigs.k8s.io/kubebuilder/v3/pkg/machinery" 23 "sigs.k8s.io/kubebuilder/v3/pkg/plugins" 24 "sigs.k8s.io/kubebuilder/v3/pkg/plugins/optional/grafana/v1alpha/scaffolds/internal/templates" 25 ) 26 27 var _ plugins.Scaffolder = &initScaffolder{} 28 29 type initScaffolder struct { 30 // fs is the filesystem that will be used by the scaffolder 31 fs machinery.Filesystem 32 } 33 34 // NewInitScaffolder returns a new Scaffolder for project initialization operations 35 func NewInitScaffolder() plugins.Scaffolder { 36 return &initScaffolder{} 37 } 38 39 // InjectFS implements cmdutil.Scaffolder 40 func (s *initScaffolder) InjectFS(fs machinery.Filesystem) { 41 s.fs = fs 42 } 43 44 // Scaffold implements cmdutil.Scaffolder 45 func (s *initScaffolder) Scaffold() error { 46 log.Println("Generating Grafana manifests to visualize controller status...") 47 48 // Initialize the machinery.Scaffold that will write the files to disk 49 scaffold := machinery.NewScaffold(s.fs) 50 51 return scaffold.Execute( 52 &templates.RuntimeManifest{}, 53 &templates.ResourcesManifest{}, 54 &templates.CustomMetricsConfigManifest{ConfigPath: string(configFilePath)}, 55 ) 56 }