diff --git a/cmd/file_handler.go b/cmd/file_handler.go index fea2443..03b2d54 100644 --- a/cmd/file_handler.go +++ b/cmd/file_handler.go @@ -4,7 +4,7 @@ import ( "fmt" "os" - "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1" + v1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" "k8s.io/apimachinery/pkg/util/yaml" "github.com/Skarlso/crd-to-sample-yaml/pkg/sanitize" @@ -14,7 +14,7 @@ type FileHandler struct { location string } -func (h *FileHandler) CRDs() ([]*v1beta1.CustomResourceDefinition, error) { +func (h *FileHandler) CRDs() ([]*v1.CustomResourceDefinition, error) { if _, err := os.Stat(h.location); os.IsNotExist(err) { return nil, fmt.Errorf("file under '%s' does not exist", h.location) } @@ -28,10 +28,10 @@ func (h *FileHandler) CRDs() ([]*v1beta1.CustomResourceDefinition, error) { return nil, fmt.Errorf("failed to sanitize content: %w", err) } - crd := &v1beta1.CustomResourceDefinition{} + crd := &v1.CustomResourceDefinition{} if err := yaml.Unmarshal(content, crd); err != nil { return nil, fmt.Errorf("failed to unmarshal into custom resource definition: %w", err) } - return []*v1beta1.CustomResourceDefinition{crd}, nil + return []*v1.CustomResourceDefinition{crd}, nil } diff --git a/cmd/folder_handler.go b/cmd/folder_handler.go index b0d833b..c16a773 100644 --- a/cmd/folder_handler.go +++ b/cmd/folder_handler.go @@ -6,7 +6,7 @@ import ( "os" "path/filepath" - "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1" + v1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" "k8s.io/apimachinery/pkg/util/yaml" "github.com/Skarlso/crd-to-sample-yaml/pkg/sanitize" @@ -16,12 +16,12 @@ type FolderHandler struct { location string } -func (h *FolderHandler) CRDs() ([]*v1beta1.CustomResourceDefinition, error) { +func (h *FolderHandler) CRDs() ([]*v1.CustomResourceDefinition, error) { if _, err := os.Stat(h.location); os.IsNotExist(err) { return nil, fmt.Errorf("file under '%s' does not exist", h.location) } - var crds []*v1beta1.CustomResourceDefinition + var crds []*v1.CustomResourceDefinition if err := filepath.Walk(h.location, func(path string, info fs.FileInfo, err error) error { if err != nil { @@ -48,7 +48,7 @@ func (h *FolderHandler) CRDs() ([]*v1beta1.CustomResourceDefinition, error) { return fmt.Errorf("failed to sanitize content: %w", err) } - crd := &v1beta1.CustomResourceDefinition{} + crd := &v1.CustomResourceDefinition{} if err := yaml.Unmarshal(content, crd); err != nil { fmt.Fprintln(os.Stderr, "skipping none CRD file: "+path) diff --git a/cmd/generate.go b/cmd/generate.go index a2cf268..a200b69 100644 --- a/cmd/generate.go +++ b/cmd/generate.go @@ -8,7 +8,7 @@ import ( "path/filepath" "github.com/spf13/cobra" - "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1" + v1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" "github.com/Skarlso/crd-to-sample-yaml/pkg" ) @@ -45,7 +45,7 @@ var ( ) type Handler interface { - CRDs() ([]*v1beta1.CustomResourceDefinition, error) + CRDs() ([]*v1.CustomResourceDefinition, error) } func init() { diff --git a/cmd/url_handler.go b/cmd/url_handler.go index 74597cb..fb9bc66 100644 --- a/cmd/url_handler.go +++ b/cmd/url_handler.go @@ -5,7 +5,7 @@ import ( "net/http" "time" - "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1" + v1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" "k8s.io/apimachinery/pkg/util/yaml" "github.com/Skarlso/crd-to-sample-yaml/pkg/fetcher" @@ -21,7 +21,7 @@ type URLHandler struct { token string } -func (h *URLHandler) CRDs() ([]*v1beta1.CustomResourceDefinition, error) { +func (h *URLHandler) CRDs() ([]*v1.CustomResourceDefinition, error) { client := http.DefaultClient client.Timeout = timeout * time.Second @@ -36,10 +36,10 @@ func (h *URLHandler) CRDs() ([]*v1beta1.CustomResourceDefinition, error) { return nil, fmt.Errorf("failed to sanitize content: %w", err) } - crd := &v1beta1.CustomResourceDefinition{} + crd := &v1.CustomResourceDefinition{} if err := yaml.Unmarshal(content, crd); err != nil { return nil, fmt.Errorf("failed to unmarshal into custom resource definition: %w", err) } - return []*v1beta1.CustomResourceDefinition{crd}, nil + return []*v1.CustomResourceDefinition{crd}, nil } diff --git a/pkg/create_html_output.go b/pkg/create_html_output.go index 8bedcf8..d67e40d 100644 --- a/pkg/create_html_output.go +++ b/pkg/create_html_output.go @@ -11,7 +11,7 @@ import ( "slices" "sort" - "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1" + v1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" ) // Version wraps a top level version resource which contains the underlying openAPIV3Schema. @@ -61,7 +61,7 @@ func LoadTemplates() error { } // RenderContent creates an HTML website from the CRD content. -func RenderContent(w io.WriteCloser, crd *v1beta1.CustomResourceDefinition, comments, minimal bool) (err error) { +func RenderContent(w io.WriteCloser, crd *v1.CustomResourceDefinition, comments, minimal bool) (err error) { defer func() { if cerr := w.Close(); cerr != nil { err = errors.Join(err, cerr) @@ -118,7 +118,7 @@ type Property struct { // parseCRD takes the properties and constructs a linked list out of the embedded properties that the recursive // template can call and construct linked divs. -func parseCRD(properties map[string]v1beta1.JSONSchemaProps, version string, minimal bool, requiredList []string) ([]*Property, error) { +func parseCRD(properties map[string]v1.JSONSchemaProps, version string, minimal bool, requiredList []string) ([]*Property, error) { output := make([]*Property, 0, len(properties)) sortedKeys := make([]string, 0, len(properties)) diff --git a/pkg/generate.go b/pkg/generate.go index a38dda5..c875498 100644 --- a/pkg/generate.go +++ b/pkg/generate.go @@ -11,7 +11,7 @@ import ( "strings" "github.com/brianvoe/gofakeit/v6" - "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1" + v1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" ) const array = "array" @@ -19,7 +19,7 @@ const array = "array" var RootRequiredFields = []string{"apiVersion", "kind", "spec", "metadata"} // Generate takes a CRD content and path, and outputs. -func Generate(crd *v1beta1.CustomResourceDefinition, w io.WriteCloser, enableComments, minimal, skipRandom bool) (err error) { +func Generate(crd *v1.CustomResourceDefinition, w io.WriteCloser, enableComments, minimal, skipRandom bool) (err error) { defer func() { if cerr := w.Close(); cerr != nil { err = errors.Join(err, cerr) @@ -77,7 +77,7 @@ func NewParser(group, kind string, comments, requiredOnly, skipRandom bool) *Par // ParseProperties takes a writer and puts out any information / properties it encounters during the runs. // It will recursively parse every "properties:" and "additionalProperties:". Using the types, it will also output // some sample data based on those types. -func (p *Parser) ParseProperties(version string, file io.Writer, properties map[string]v1beta1.JSONSchemaProps, requiredFields []string) error { +func (p *Parser) ParseProperties(version string, file io.Writer, properties map[string]v1.JSONSchemaProps, requiredFields []string) error { sortedKeys := make([]string, 0, len(properties)) for k := range properties { sortedKeys = append(sortedKeys, k) @@ -176,7 +176,7 @@ func (p *Parser) ParseProperties(version string, file io.Writer, properties map[ } // outputValueType generate an output value based on the given type. -func outputValueType(v v1beta1.JSONSchemaProps, skipRandom bool) string { +func outputValueType(v v1.JSONSchemaProps, skipRandom bool) string { if v.Default != nil { return string(v.Default.Raw) } diff --git a/pkg/generate_test.go b/pkg/generate_test.go index 8feb06f..9898399 100644 --- a/pkg/generate_test.go +++ b/pkg/generate_test.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1" + v1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" "k8s.io/apimachinery/pkg/util/yaml" ) @@ -16,7 +16,7 @@ func TestGenerate(t *testing.T) { content, err := os.ReadFile(filepath.Join("testdata", "sample_crd.yaml")) require.NoError(t, err) - crd := &v1beta1.CustomResourceDefinition{} + crd := &v1.CustomResourceDefinition{} require.NoError(t, yaml.Unmarshal(content, crd)) var output []byte @@ -36,7 +36,7 @@ func TestGenerateWithExample(t *testing.T) { content, err := os.ReadFile(filepath.Join("testdata", "sample_crd_with_example.yaml")) require.NoError(t, err) - crd := &v1beta1.CustomResourceDefinition{} + crd := &v1.CustomResourceDefinition{} require.NoError(t, yaml.Unmarshal(content, crd)) var output []byte @@ -56,7 +56,7 @@ func TestGenerateWithComments(t *testing.T) { content, err := os.ReadFile(filepath.Join("testdata", "sample_crd.yaml")) require.NoError(t, err) - crd := &v1beta1.CustomResourceDefinition{} + crd := &v1.CustomResourceDefinition{} require.NoError(t, yaml.Unmarshal(content, crd)) var output []byte @@ -76,7 +76,7 @@ func TestGenerateMinimal(t *testing.T) { content, err := os.ReadFile(filepath.Join("testdata", "sample_crd.yaml")) require.NoError(t, err) - crd := &v1beta1.CustomResourceDefinition{} + crd := &v1.CustomResourceDefinition{} require.NoError(t, yaml.Unmarshal(content, crd)) var output []byte @@ -96,7 +96,7 @@ func TestGenerateMinimalWithExample(t *testing.T) { content, err := os.ReadFile(filepath.Join("testdata", "sample_crd_with_example.yaml")) require.NoError(t, err) - crd := &v1beta1.CustomResourceDefinition{} + crd := &v1.CustomResourceDefinition{} require.NoError(t, yaml.Unmarshal(content, crd)) var output []byte @@ -116,7 +116,7 @@ func TestGenerateWithAdditionalProperties(t *testing.T) { content, err := os.ReadFile(filepath.Join("testdata", "sample_crd_with_additional_properties.yaml")) require.NoError(t, err) - crd := &v1beta1.CustomResourceDefinition{} + crd := &v1.CustomResourceDefinition{} require.NoError(t, yaml.Unmarshal(content, crd)) var output []byte diff --git a/pkg/matches/matchsnapshot/update.go b/pkg/matches/matchsnapshot/update.go index 8a94677..d0230d8 100644 --- a/pkg/matches/matchsnapshot/update.go +++ b/pkg/matches/matchsnapshot/update.go @@ -6,7 +6,7 @@ import ( "path/filepath" "strings" - "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1" + v1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" "k8s.io/apimachinery/pkg/util/yaml" "github.com/Skarlso/crd-to-sample-yaml/pkg" @@ -30,7 +30,7 @@ func (u *Update) Update(sourceTemplateLocation string, targetSnapshotLocation st } baseName := strings.Trim(filepath.Base(sourceTemplateLocation), filepath.Ext(sourceTemplateLocation)) - crd := &v1beta1.CustomResourceDefinition{} + crd := &v1.CustomResourceDefinition{} if err := yaml.Unmarshal(sourceTemplate, crd); err != nil { return fmt.Errorf("failed to unmarshal into custom resource definition: %w", err) } diff --git a/wasm/app.go b/wasm/app.go index 4bee528..e4933ff 100644 --- a/wasm/app.go +++ b/wasm/app.go @@ -11,7 +11,7 @@ import ( "strings" "github.com/maxence-charriere/go-app/v10/pkg/app" - "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1" + v1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" "k8s.io/apimachinery/pkg/util/yaml" "github.com/Skarlso/crd-to-sample-yaml/pkg" @@ -108,7 +108,7 @@ func (h *crdView) Render() app.UI { return h.buildError(h.preRenderErr) } - crd := &v1beta1.CustomResourceDefinition{} + crd := &v1.CustomResourceDefinition{} if err := yaml.Unmarshal(h.content, crd); err != nil { return h.buildError(err) } @@ -289,7 +289,7 @@ func render(d app.UI, p []*Property, accordionID string) app.UI { // parseCRD takes the properties and constructs a linked list out of the embedded properties that the recursive // template can call and construct linked divs. -func parseCRD(properties map[string]v1beta1.JSONSchemaProps, version string, requiredList []string, minimal bool) ([]*Property, error) { +func parseCRD(properties map[string]v1.JSONSchemaProps, version string, requiredList []string, minimal bool) ([]*Property, error) { sortedKeys := make([]string, 0, len(properties)) output := make([]*Property, 0, len(properties))