generated from cybozu-go/neco-template
-
Notifications
You must be signed in to change notification settings - Fork 6
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 #132 from erikgb/serve-v2
feat: start serving v2 API
- Loading branch information
Showing
15 changed files
with
328 additions
and
35 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
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) | ||
} |
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,3 +1,4 @@ | ||
// +kubebuilder:object:generate=true | ||
// +groupName=accurate.cybozu.com | ||
// +k8s:conversion-gen=github.com/cybozu-go/accurate/api/accurate/v2alpha1 | ||
package v2 |
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,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(), | ||
) | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.