Skip to content

Commit

Permalink
feat: start serving v2 API
Browse files Browse the repository at this point in the history
  • Loading branch information
erikgb committed Jun 7, 2024
1 parent 0d762dc commit 404a407
Show file tree
Hide file tree
Showing 8 changed files with 240 additions and 3 deletions.
29 changes: 29 additions & 0 deletions api/accurate/v2/conversion_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package v2

import (
"testing"

accuratev2alpha1 "github.com/cybozu-go/accurate/api/accurate/v2alpha1"
utilconversion "github.com/cybozu-go/accurate/internal/util/conversion"
fuzz "github.com/google/gofuzz"
"k8s.io/apimachinery/pkg/api/apitesting/fuzzer"
runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer"
)

func TestFuzzyConversion(t *testing.T) {
t.Run("for SubNamespace", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{
Hub: &accuratev2alpha1.SubNamespace{},
Spoke: &SubNamespace{},
FuzzerFuncs: []fuzzer.FuzzerFuncs{SubNamespaceStatusFuzzFunc},
}))
}

func SubNamespaceStatusFuzzFunc(_ runtimeserializer.CodecFactory) []interface{} {
return []interface{}{
SubNamespaceStatusFuzzer,
}
}

func SubNamespaceStatusFuzzer(in *SubNamespace, c fuzz.Continue) {
c.FuzzNoCustom(in)
}
1 change: 1 addition & 0 deletions api/accurate/v2/doc.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// +kubebuilder:object:generate=true
// +groupName=accurate.cybozu.com
// +k8s:conversion-gen=github.com/cybozu-go/accurate/api/accurate/v2alpha1
package v2
2 changes: 2 additions & 0 deletions api/accurate/v2/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ var (

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme

localSchemeBuilder = SchemeBuilder.SchemeBuilder
)
43 changes: 43 additions & 0 deletions api/accurate/v2/subnamespace_conversion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package v2

import (
accuratev2alpha1 "github.com/cybozu-go/accurate/api/accurate/v2alpha1"
"github.com/go-logr/logr"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/conversion"
)

// ConvertTo converts this SubNamespace to the Hub version (v2alpha1).
func (src *SubNamespace) ConvertTo(dstRaw conversion.Hub) error {
dst := dstRaw.(*accuratev2alpha1.SubNamespace)

logger := getConversionLogger(src).WithValues(
"source", SchemeGroupVersion.Version,
"destination", accuratev2alpha1.SchemeGroupVersion.Version,
)
logger.V(5).Info("converting")

return Convert_v2_SubNamespace_To_v2alpha1_SubNamespace(src, dst, nil)
}

// ConvertFrom converts from the Hub version (v2alpha1) to this version.
func (dst *SubNamespace) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*accuratev2alpha1.SubNamespace)

logger := getConversionLogger(src).WithValues(
"source", accuratev2alpha1.SchemeGroupVersion.Version,
"destination", SchemeGroupVersion.Version,
)
logger.V(5).Info("converting")

return Convert_v2alpha1_SubNamespace_To_v2_SubNamespace(src, dst, nil)
}

func getConversionLogger(obj client.Object) logr.Logger {
return ctrl.Log.WithName("conversion").WithValues(
"kind", "SubNamespace",
"namespace", obj.GetNamespace(),
"name", obj.GetName(),
)
}
1 change: 0 additions & 1 deletion api/accurate/v2/subnamespace_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ type SubNamespaceSpec struct {
}

//+kubebuilder:object:root=true
//+kubebuilder:unservedversion
//+kubebuilder:subresource:status
//+genclient

Expand Down
163 changes: 163 additions & 0 deletions api/accurate/v2/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion charts/accurate/templates/generated/crds.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion config/crd/bases/accurate.cybozu.com_subnamespaces.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 404a407

Please sign in to comment.