Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bump): use in codebase v1.CustomResourceDefinition #102

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions cmd/file_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
}
Expand All @@ -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
}
8 changes: 4 additions & 4 deletions cmd/folder_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand All @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -45,7 +45,7 @@ var (
)

type Handler interface {
CRDs() ([]*v1beta1.CustomResourceDefinition, error)
CRDs() ([]*v1.CustomResourceDefinition, error)
}

func init() {
Expand Down
8 changes: 4 additions & 4 deletions cmd/url_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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

Expand All @@ -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
}
6 changes: 3 additions & 3 deletions pkg/create_html_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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))

Expand Down
8 changes: 4 additions & 4 deletions pkg/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ 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"

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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ 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"
)

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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/matches/matchsnapshot/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
}
Expand Down
6 changes: 3 additions & 3 deletions wasm/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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))

Expand Down