sigs.k8s.io/kubebuilder/v3@v3.14.0/cmd/main.go (about)

     1  /*
     2  Copyright 2017 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  	"github.com/sirupsen/logrus"
    21  	"github.com/spf13/afero"
    22  	"sigs.k8s.io/kubebuilder/v3/pkg/cli"
    23  	cfgv2 "sigs.k8s.io/kubebuilder/v3/pkg/config/v2"
    24  	cfgv3 "sigs.k8s.io/kubebuilder/v3/pkg/config/v3"
    25  	"sigs.k8s.io/kubebuilder/v3/pkg/machinery"
    26  	"sigs.k8s.io/kubebuilder/v3/pkg/plugin"
    27  	kustomizecommonv1 "sigs.k8s.io/kubebuilder/v3/pkg/plugins/common/kustomize/v1"
    28  	kustomizecommonv2alpha "sigs.k8s.io/kubebuilder/v3/pkg/plugins/common/kustomize/v2"
    29  	"sigs.k8s.io/kubebuilder/v3/pkg/plugins/golang"
    30  
    31  	//nolint:staticcheck
    32  	declarativev1 "sigs.k8s.io/kubebuilder/v3/pkg/plugins/golang/declarative/v1"
    33  	deployimagev1alpha1 "sigs.k8s.io/kubebuilder/v3/pkg/plugins/golang/deploy-image/v1alpha1"
    34  	golangv2 "sigs.k8s.io/kubebuilder/v3/pkg/plugins/golang/v2"
    35  	golangv3 "sigs.k8s.io/kubebuilder/v3/pkg/plugins/golang/v3"
    36  	golangv4 "sigs.k8s.io/kubebuilder/v3/pkg/plugins/golang/v4"
    37  	grafanav1alpha1 "sigs.k8s.io/kubebuilder/v3/pkg/plugins/optional/grafana/v1alpha"
    38  )
    39  
    40  func init() {
    41  	// Disable timestamps on the default TextFormatter
    42  	logrus.SetFormatter(&logrus.TextFormatter{DisableTimestamp: true})
    43  }
    44  
    45  func main() {
    46  
    47  	const deprecateMessageGoV3Bundle = "This version is deprecated." +
    48  		"The `go/v3` cannot scaffold projects using kustomize versions v4x+" +
    49  		" and cannot fully support Kubernetes 1.25+." +
    50  		"It is recommended to upgrade your project to the latest versions available (go/v4)." +
    51  		"Please, check the migration guide to learn how to upgrade your project"
    52  
    53  	// Bundle plugin which built the golang projects scaffold by Kubebuilder go/v3
    54  	gov3Bundle, _ := plugin.NewBundleWithOptions(plugin.WithName(golang.DefaultNameQualifier),
    55  		plugin.WithVersion(plugin.Version{Number: 3}),
    56  		plugin.WithDeprecationMessage(deprecateMessageGoV3Bundle),
    57  		plugin.WithPlugins(kustomizecommonv1.Plugin{}, golangv3.Plugin{}),
    58  	)
    59  
    60  	// Bundle plugin which built the golang projects scaffold by Kubebuilder go/v4 with kustomize alpha-v2
    61  	gov4Bundle, _ := plugin.NewBundleWithOptions(plugin.WithName(golang.DefaultNameQualifier),
    62  		plugin.WithVersion(plugin.Version{Number: 4}),
    63  		plugin.WithPlugins(kustomizecommonv2alpha.Plugin{}, golangv4.Plugin{}),
    64  	)
    65  
    66  	fs := machinery.Filesystem{
    67  		FS: afero.NewOsFs(),
    68  	}
    69  	externalPlugins, err := cli.DiscoverExternalPlugins(fs.FS)
    70  	if err != nil {
    71  		logrus.Error(err)
    72  	}
    73  
    74  	c, err := cli.New(
    75  		cli.WithCommandName("kubebuilder"),
    76  		cli.WithVersion(versionString()),
    77  		cli.WithPlugins(
    78  			golangv2.Plugin{},
    79  			golangv3.Plugin{},
    80  			golangv4.Plugin{},
    81  			gov3Bundle,
    82  			gov4Bundle,
    83  			&kustomizecommonv1.Plugin{},
    84  			&kustomizecommonv2alpha.Plugin{},
    85  			&declarativev1.Plugin{},
    86  			&deployimagev1alpha1.Plugin{},
    87  			&grafanav1alpha1.Plugin{},
    88  		),
    89  		cli.WithPlugins(externalPlugins...),
    90  		cli.WithDefaultPlugins(cfgv2.Version, golangv2.Plugin{}),
    91  		cli.WithDefaultPlugins(cfgv3.Version, gov4Bundle),
    92  		cli.WithDefaultProjectVersion(cfgv3.Version),
    93  		cli.WithCompletion(),
    94  	)
    95  	if err != nil {
    96  		logrus.Fatal(err)
    97  	}
    98  	if err := c.Run(); err != nil {
    99  		logrus.Fatal(err)
   100  	}
   101  }