-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
Signed-off-by: Tamal Saha <[email protected]>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
$HOME/go/src/github.com/crossplane/crossplane/cluster/crds | ||
$HOME/go/src/github.com/jetstack/cert-manager/deploy/crds | ||
$HOME/go/src/github.com/kubernetes-csi/external-snapshotter/client/config/crd | ||
$HOME/go/src/github.com/open-policy-agent/gatekeeper/config/crd/bases | ||
$HOME/go/src/github.com/prometheus-operator/prometheus-operator/example/prometheus-operator-crd | ||
$HOME/go/src/github.com/upbound/provider-aws/package/crds | ||
$HOME/go/src/github.com/upbound/provider-azure/package/crds | ||
$HOME/go/src/github.com/upbound/provider-gcp/package/crds | ||
$HOME/go/src/go.kubeware.dev/catalog/config/crd/bases | ||
$HOME/go/src/go.openviz.dev/grafana-tools/crds | ||
$HOME/go/src/k8s.io/api/crds | ||
$HOME/go/src/k8s.io/autoscaler/vertical-pod-autoscaler/deploy/vpa-v1-crd-gen.yaml | ||
$HOME/go/src/k8s.io/autoscaler/vertical-pod-autoscaler/deploy/vpa-v1-crd.yaml | ||
$HOME/go/src/k8s.io/kube-aggregator/crds | ||
$HOME/go/src/kmodules.xyz/custom-resources/crds | ||
$HOME/go/src/kmodules.xyz/resource-metadata/crds | ||
$HOME/go/src/kubedb.dev/apimachinery/crds | ||
$HOME/go/src/kubeform.dev/provider-aws/package/crds | ||
$HOME/go/src/kubeform.dev/provider-azure/package/crds | ||
$HOME/go/src/kubeform.dev/provider-gcp/package/crds | ||
$HOME/go/src/kubeops.dev/external-dns-operator/crds | ||
$HOME/go/src/kubeops.dev/falco-ui-server/crds | ||
$HOME/go/src/kubeops.dev/supervisor/crds | ||
$HOME/go/src/kubeops.dev/ui-server/crds | ||
$HOME/go/src/kubevault.dev/apimachinery/crds | ||
$HOME/go/src/open-cluster-management.io/api/addon/v1alpha1 | ||
$HOME/go/src/open-cluster-management.io/api/cluster/v1 | ||
$HOME/go/src/open-cluster-management.io/api/cluster/v1alpha1 | ||
$HOME/go/src/open-cluster-management.io/api/cluster/v1beta1 | ||
$HOME/go/src/open-cluster-management.io/api/cluster/v1beta2 | ||
$HOME/go/src/open-cluster-management.io/api/crdsv1beta1 | ||
$HOME/go/src/open-cluster-management.io/api/operator/v1 | ||
$HOME/go/src/open-cluster-management.io/api/work/v1 | ||
$HOME/go/src/open-cluster-management.io/api/work/v1alpha1 | ||
$HOME/go/src/sigs.k8s.io/cluster-api-provider-aws/config/crd/bases | ||
$HOME/go/src/sigs.k8s.io/cluster-api-provider-azure/config/crd/bases | ||
$HOME/go/src/sigs.k8s.io/cluster-api-provider-gcp/config/crd/bases | ||
$HOME/go/src/sigs.k8s.io/cluster-api/config/crd/bases | ||
$HOME/go/src/sigs.k8s.io/secrets-store-csi-driver/charts/secrets-store-csi-driver/crds | ||
$HOME/go/src/stash.appscode.dev/apimachinery/crds | ||
$HOME/go/src/stash.appscode.dev/ui-server/crds | ||
$HOME/go/src/voyagermesh.dev/apimachinery/crds | ||
$HOME/go/src/voyagermesh.dev/installer/charts/gateway-helm/crds | ||
$HOME/go/src/voyagermesh.dev/installer/charts/gateway-helm/crds/generated | ||
$HOME/go/src/voyagermesh.dev/installer/charts/gateway-helm/crds/voyager | ||
$HOME/go/src/x-helm.dev/apimachinery/crds |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,287 @@ | ||
/* | ||
Copyright AppsCode Inc. and Contributors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"net/url" | ||
"os" | ||
"path/filepath" | ||
"runtime" | ||
"strings" | ||
|
||
"kmodules.xyz/client-go/tools/parser" | ||
"kmodules.xyz/resource-metadata/hub/resourcedescriptors" | ||
"kmodules.xyz/resource-metadata/hub/resourceeditors" | ||
|
||
"github.com/pkg/errors" | ||
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions" | ||
crdv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" | ||
crdv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"sigs.k8s.io/yaml" | ||
) | ||
|
||
func main() { | ||
dir := "/Users/tamal/go/src/go.crdhub.dev/crdhub/public" | ||
os.MkdirAll(dir, 0o755) | ||
Check failure on line 45 in cmd/gen-docs/main.go GitHub Actions / k8s (v1.20.15)
|
||
GenDescriptor(dir) | ||
Check failure on line 46 in cmd/gen-docs/main.go GitHub Actions / k8s (v1.20.15)
|
||
GenResourceEditor(dir) | ||
Check failure on line 47 in cmd/gen-docs/main.go GitHub Actions / k8s (v1.20.15)
|
||
ImportCRD(dir) | ||
Check failure on line 48 in cmd/gen-docs/main.go GitHub Actions / k8s (v1.20.15)
|
||
} | ||
|
||
func GenDescriptor(dir string) error { | ||
for _, rd := range resourcedescriptors.List() { | ||
g := rd.Spec.Resource.Group | ||
if g == "" { | ||
g = "core" | ||
} | ||
r := rd.Spec.Resource.Name | ||
|
||
rdir := filepath.Join(dir, g, r) | ||
os.MkdirAll(rdir, 0o755) | ||
Check failure on line 60 in cmd/gen-docs/main.go GitHub Actions / k8s (v1.20.15)
|
||
|
||
// os.WriteFile(filepath.Join(rdir, "crd.yaml"), []byte("crd.yaml"), 0644) | ||
|
||
vdir := filepath.Join(rdir, rd.Spec.Resource.Version) | ||
os.MkdirAll(vdir, 0o755) | ||
Check failure on line 65 in cmd/gen-docs/main.go GitHub Actions / k8s (v1.20.15)
|
||
|
||
data, err := yaml.Marshal(rd) | ||
if err != nil { | ||
return err | ||
} | ||
os.WriteFile(filepath.Join(vdir, "resourcedescriptor.yaml"), data, 0o644) | ||
Check failure on line 71 in cmd/gen-docs/main.go GitHub Actions / k8s (v1.20.15)
|
||
|
||
if rd.Spec.Validation != nil && rd.Spec.Validation.OpenAPIV3Schema != nil { | ||
data, err := yaml.Marshal(rd.Spec.Validation.OpenAPIV3Schema) | ||
if err != nil { | ||
return err | ||
} | ||
os.WriteFile(filepath.Join(vdir, "openapiv3_schema.yaml"), data, 0o644) | ||
Check failure on line 78 in cmd/gen-docs/main.go GitHub Actions / k8s (v1.20.15)
|
||
} | ||
} | ||
return nil | ||
} | ||
|
||
func GenResourceEditor(dir string) error { | ||
for _, rd := range resourceeditors.List() { | ||
g := rd.Spec.Resource.Group | ||
if g == "" { | ||
g = "core" | ||
} | ||
r := rd.Spec.Resource.Name | ||
|
||
rdir := filepath.Join(dir, g, r) | ||
os.MkdirAll(rdir, 0o755) | ||
|
||
// os.WriteFile(filepath.Join(rdir, "crd.yaml"), []byte("crd.yaml"), 0644) | ||
|
||
vdir := filepath.Join(rdir, rd.Spec.Resource.Version) | ||
os.MkdirAll(vdir, 0o755) | ||
|
||
data, err := yaml.Marshal(rd) | ||
if err != nil { | ||
return err | ||
} | ||
os.WriteFile(filepath.Join(vdir, "resourceeditor.yaml"), data, 0o644) | ||
Check failure on line 104 in cmd/gen-docs/main.go GitHub Actions / k8s (v1.20.15)
|
||
} | ||
return nil | ||
} | ||
|
||
func ImportUIWizards() { | ||
} | ||
|
||
/* | ||
# Add icons | ||
go run cmd/icon-namer/main.go | ||
# Import crds | ||
# FluxCD CRDs | ||
# helm template flux fluxcd-community/flux2 --output-dir=/tmp/fluxcd-manifests | ||
/tmp/fluxcd-manifests | ||
*/ | ||
func ImportCRD(dir string) error { | ||
_, f2, _, ok := runtime.Caller(1) | ||
if !ok { | ||
return errors.New("can't detect crd_list.txt file location") | ||
} | ||
fmt.Println(f2) | ||
|
||
data, err := os.ReadFile(filepath.Join(filepath.Dir(f2), "crd_list.txt")) | ||
if err != nil { | ||
return err | ||
} | ||
lines := strings.Split(string(data), "\n") | ||
for _, line := range lines { | ||
line = strings.TrimSpace(line) | ||
if line == "" { | ||
continue | ||
} | ||
line = os.ExpandEnv(line) | ||
processLocation(dir, line) | ||
} | ||
return nil | ||
} | ||
|
||
func processLocation(dir, location string) error { | ||
u, err := url.Parse(location) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if u.Scheme != "" { | ||
resp, err := http.Get(u.String()) | ||
if err != nil { | ||
return err | ||
} | ||
defer func() { _ = resp.Body.Close() }() | ||
var buf bytes.Buffer | ||
_, err = io.Copy(&buf, resp.Body) | ||
if err != nil { | ||
return err | ||
} | ||
return parser.ProcessResources(buf.Bytes(), processObject(dir)) | ||
} else { | ||
fi, err := os.Stat(location) | ||
if err != nil { | ||
return err | ||
} | ||
if fi.IsDir() { | ||
ext := crdFileExtension(location) | ||
|
||
err = filepath.Walk(location, func(path string, info os.FileInfo, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
if info.IsDir() { | ||
return nil | ||
} | ||
if !strings.HasSuffix(info.Name(), ext) { | ||
return nil | ||
} | ||
|
||
data, err := os.ReadFile(path) | ||
if err != nil { | ||
return err | ||
} | ||
return parser.ProcessResources(data, processObject(dir)) | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
} else { | ||
data, err := os.ReadFile(location) | ||
if err != nil { | ||
return err | ||
} | ||
crd, err := CustomResourceDefinition(data) | ||
if err != nil { | ||
return err | ||
} | ||
err = WriteDescriptor(dir, crd) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func CustomResourceDefinition(data []byte) (*crdv1.CustomResourceDefinition, error) { | ||
var tm metav1.TypeMeta | ||
err := yaml.Unmarshal(data, &tm) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if tm.APIVersion == crdv1.SchemeGroupVersion.String() { | ||
var out crdv1.CustomResourceDefinition | ||
err := yaml.Unmarshal(data, &out) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &out, nil | ||
} | ||
|
||
var defv1 crdv1beta1.CustomResourceDefinition | ||
err = yaml.Unmarshal(data, &defv1) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var inner apiextensions.CustomResourceDefinition | ||
err = crdv1beta1.Convert_v1beta1_CustomResourceDefinition_To_apiextensions_CustomResourceDefinition(&defv1, &inner, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var out crdv1.CustomResourceDefinition | ||
err = crdv1.Convert_apiextensions_CustomResourceDefinition_To_v1_CustomResourceDefinition(&inner, &out, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &out, nil | ||
} | ||
|
||
func processObject(dir string) func(ri parser.ResourceInfo) error { | ||
return func(ri parser.ResourceInfo) error { | ||
data, err := json.Marshal(ri.Object) | ||
if err != nil { | ||
return err | ||
} | ||
crd, err := CustomResourceDefinition(data) | ||
if err != nil { | ||
return err | ||
} | ||
err = WriteDescriptor(dir, crd) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
} | ||
|
||
func crdFileExtension(dir string) string { | ||
entries, err := os.ReadDir(dir) | ||
if err != nil { | ||
panic(err) | ||
} | ||
for _, entry := range entries { | ||
if entry.IsDir() { | ||
continue | ||
} | ||
if strings.HasSuffix(entry.Name(), ".v1.yaml") { | ||
return ".v1.yaml" | ||
} | ||
} | ||
return ".yaml" | ||
} | ||
|
||
func WriteDescriptor(dir string, crd *crdv1.CustomResourceDefinition) error { | ||
rdir := filepath.Join(dir, crd.Spec.Group, crd.Spec.Names.Plural) | ||
os.MkdirAll(rdir, 0o755) | ||
data, err := yaml.Marshal(crd) | ||
if err != nil { | ||
return err | ||
} | ||
os.WriteFile(filepath.Join(rdir, "crd.yaml"), data, 0o644) | ||
return nil | ||
} |