...

Source file src/github.com/GoogleCloudPlatform/k8s-config-connector/scripts/client-gen/main.go

Documentation: github.com/GoogleCloudPlatform/k8s-config-connector/scripts/client-gen

     1  /*
     2  Copyright 2015 The Kubernetes Authors.
     3  Licensed under the Apache License, Version 2.0 (the "License");
     4  you may not use this file except in compliance with the License.
     5  You may obtain a copy of the License at
     6      http://www.apache.org/licenses/LICENSE-2.0
     7  Unless required by applicable law or agreed to in writing, software
     8  distributed under the License is distributed on an "AS IS" BASIS,
     9  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    10  See the License for the specific language governing permissions and
    11  limitations under the License.
    12  */
    13  
    14  // client-gen makes the individual typed clients using gengo.
    15  
    16  // This code is duplicated from https://github.com/kubernetes/code-generator/blob/master/cmd/client-gen/main.go
    17  // so that this repository can utilize the client-gen functionality.
    18  package main
    19  
    20  import (
    21  	"flag"
    22  	"path/filepath"
    23  
    24  	"github.com/spf13/pflag"
    25  	generatorargs "k8s.io/code-generator/cmd/client-gen/args"
    26  	"k8s.io/code-generator/cmd/client-gen/generators"
    27  	"k8s.io/code-generator/pkg/util"
    28  	"k8s.io/gengo/args"
    29  	"k8s.io/klog/v2"
    30  )
    31  
    32  func main() {
    33  	klog.InitFlags(nil)
    34  	genericArgs, customArgs := generatorargs.NewDefaults()
    35  
    36  	// Override defaults.
    37  	// TODO: move this out of client-gen
    38  	genericArgs.GoHeaderFilePath = filepath.Join(args.DefaultSourceTree(), util.BoilerplatePath())
    39  
    40  	genericArgs.AddFlags(pflag.CommandLine)
    41  	customArgs.AddFlags(pflag.CommandLine, "") // TODO: move this input path out of client-gen
    42  	flag.Set("logtostderr", "true")
    43  	pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
    44  	pflag.Parse()
    45  
    46  	// add group version package as input dirs for gengo
    47  	for _, pkg := range customArgs.Groups {
    48  		for _, v := range pkg.Versions {
    49  			genericArgs.InputDirs = append(genericArgs.InputDirs, v.Package)
    50  		}
    51  	}
    52  
    53  	if err := generatorargs.Validate(genericArgs); err != nil {
    54  		klog.Fatalf("Error: %v", err)
    55  	}
    56  
    57  	if err := genericArgs.Execute(
    58  		generators.NameSystems(util.PluralExceptionListToMapOrDie(customArgs.PluralExceptions)),
    59  		generators.DefaultNameSystem(),
    60  		generators.Packages,
    61  	); err != nil {
    62  		klog.Fatalf("Error: %v", err)
    63  	}
    64  }
    65  

View as plain text