Skip to content

Commit

Permalink
Merge pull request #840 from bnallapeta/pullcrds_bycrdname
Browse files Browse the repository at this point in the history
✨ Add a flag to crd-puller to specify only the required CRDs that needs to be synced
  • Loading branch information
openshift-merge-robot authored Mar 3, 2023
2 parents eb6f243 + e91e7e2 commit de6312b
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions cmd/crd-puller/pull-crds.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ import (
)

func main() {
var (
kubeconfigPath = ".kubeconfig"
resourcesToSync []string
)
cmd := &cobra.Command{
Use: "pull-crds",
Aliases: []string{},
Expand All @@ -45,8 +49,16 @@ func main() {
`),
Example: "",
RunE: func(cmd *cobra.Command, args []string) error {
kubeconfigPath := cmd.Flag("kubeconfig").Value.String()
config, err := clientcmd.BuildConfigFromFlags("", kubeconfigPath)
loadingRules := clientcmd.NewDefaultClientConfigLoadingRules()
loadingRules.ExplicitPath = kubeconfigPath

startingConfig, err := loadingRules.GetStartingConfig()
if err != nil {
return err
}

config, err := clientcmd.NewDefaultClientConfig(*startingConfig, nil).ClientConfig()

if err != nil {
return err
}
Expand All @@ -64,7 +76,7 @@ func main() {
if err != nil {
return err
}
crds, err := puller.PullCRDs(context.TODO(), args...)
crds, err := puller.PullCRDs(context.TODO(), resourcesToSync...)
if err != nil {
return err
}
Expand All @@ -81,8 +93,8 @@ func main() {
},
}

cmd.Flags().String("kubeconfig", ".kubeconfig", "kubeconfig file used to contact the cluster.")

cmd.Flags().StringVar(&kubeconfigPath, "kubeconfig", kubeconfigPath, "kubeconfig file used to contact the cluster.")
cmd.Flags().StringSliceVarP(&resourcesToSync, "resources", "r", resourcesToSync, "Resources to pull")
help.FitTerminal(cmd.OutOrStdout())

if err := cmd.Execute(); err != nil {
Expand Down

0 comments on commit de6312b

Please sign in to comment.