-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from onmetal/refactoring
Refactored repo name and added crd puller
- Loading branch information
Showing
26 changed files
with
742 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
|
||
"github.com/onmetal/onmetal-api/pkg/cmd/help" | ||
crdpuller "github.com/onmetal/onmetal-api/pkg/crdpuller" | ||
"github.com/spf13/cobra" | ||
"k8s.io/client-go/tools/clientcmd" | ||
"sigs.k8s.io/yaml" | ||
) | ||
|
||
func main() { | ||
help.FitTerminal() | ||
cmd := &cobra.Command{ | ||
Use: "pull-crds", | ||
Aliases: []string{}, | ||
SuggestFor: []string{}, | ||
Short: "Pull CRDs from a Kubernetes cluster", | ||
Long: help.Doc(` | ||
Pull CRDs from a Kubernetes cluster | ||
Based on a kubeconfig file, it uses discovery API and the OpenAPI v2 | ||
model on the cluster to build CRDs for a list of api resource names. | ||
`), | ||
Example: "", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
kubeconfigPath := cmd.Flag("kubeconfig").Value.String() | ||
config, err := clientcmd.BuildConfigFromFlags("", kubeconfigPath) | ||
if err != nil { | ||
return err | ||
} | ||
puller, err := crdpuller.NewSchemaPuller(config) | ||
if err != nil { | ||
return err | ||
} | ||
crds, err := puller.PullCRDs(context.TODO(), args...) | ||
if err != nil { | ||
return err | ||
} | ||
for name, crd := range crds { | ||
yamlBytes, err := yaml.Marshal(crd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
ioutil.WriteFile(name+".yaml", []byte(yamlBytes), os.ModePerm) | ||
} | ||
return nil | ||
}, | ||
} | ||
cmd.Flags().String("kubeconfig", ".kubeconfig", "kubeconfig file used to contact the cluster.") | ||
|
||
if err := cmd.Execute(); err != nil { | ||
fmt.Fprintf(os.Stderr, "error: %v\n", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,20 @@ | ||
module github.com/onmetal-api | ||
module github.com/onmetal/onmetal-api | ||
|
||
go 1.15 | ||
go 1.16 | ||
|
||
require ( | ||
github.com/MakeNowJust/heredoc v1.0.0 | ||
github.com/go-logr/logr v0.4.0 | ||
github.com/muesli/reflow v0.1.0 | ||
github.com/onsi/ginkgo v1.16.2 | ||
github.com/onsi/gomega v1.12.0 | ||
k8s.io/apimachinery v0.21.1 | ||
github.com/spf13/cobra v1.1.1 | ||
github.com/wayneashleyberry/terminal-dimensions v1.0.0 | ||
k8s.io/apiextensions-apiserver v0.20.1 | ||
k8s.io/apimachinery v0.20.2 | ||
k8s.io/client-go v0.20.2 | ||
k8s.io/klog v0.0.0-20181102134211-b9b56d5dfc92 | ||
k8s.io/kube-openapi v0.0.0-20210305001622-591a79e4bda7 | ||
sigs.k8s.io/controller-runtime v0.8.3 | ||
sigs.k8s.io/yaml v1.2.0 | ||
) |
Oops, something went wrong.