Skip to content

Commit

Permalink
feat: add search api group (#11)
Browse files Browse the repository at this point in the history
#### What type of PR is this?
/kind feature

#### What this PR does / why we need it:
add search api group
  • Loading branch information
panshuai111 authored Apr 11, 2023
1 parent daa1744 commit b5116e4
Show file tree
Hide file tree
Showing 30 changed files with 849 additions and 30 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ include go.mk
APPROOT=karbour
GOSOURCE_PATHS = ./pkg/...

.PHONY: update-codegen
update-codegen: ## Update generated code
hack/update-codegen.sh

## Build-related targets
.PHONY: build-all
Expand Down
4 changes: 2 additions & 2 deletions hack/update-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ util:create_gopath_tree "${REPO_ROOT}" "${tmp_go_path}"
# instead of the $GOPATH directly. For normal projects this can be dropped.
bash "${CODEGEN_PKG}/generate-groups.sh" all \
github.com/KusionStack/karbour/pkg/generated github.com/KusionStack/karbour/pkg/apis \
"cluster:v1beta1" \
"cluster:v1beta1 search:v1beta1" \
--output-base "${tmp_go_path}" \
--go-header-file "${REPO_ROOT}"/hack/boilerplate.go.txt

bash "${CODEGEN_PKG}/generate-internal-groups.sh" "deepcopy,defaulter,conversion,openapi" \
github.com/KusionStack/karbour/pkg/generated github.com/KusionStack/karbour/pkg/apis github.com/KusionStack/karbour/pkg/apis \
"cluster:v1beta1" \
"cluster:v1beta1 search:v1beta1" \
--output-base "${tmp_go_path}" \
--go-header-file "${REPO_ROOT}/hack/boilerplate.go.txt"

Expand Down
21 changes: 21 additions & 0 deletions pkg/apis/search/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
Copyright The Karbour Authors.
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.
*/

// +k8s:deepcopy-gen=package
// +groupName=search.karbour.com

// Package search is the internal version of the API.
package search // import "github.com/KusionStack/karbour/pkg/apis/search"
26 changes: 26 additions & 0 deletions pkg/apis/search/fuzzer/fuzzer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
Copyright The Karbour Authors.
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 fuzzer

import (
runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer"
)

// Funcs returns the fuzzer functions for the apps api group.
var Funcs = func(codecs runtimeserializer.CodecFactory) []interface{} {
return []interface{}{}
}
31 changes: 31 additions & 0 deletions pkg/apis/search/install/install.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
Copyright The Karbour Authors.
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 install

import (
"github.com/KusionStack/karbour/pkg/apis/search"
"github.com/KusionStack/karbour/pkg/apis/search/v1beta1"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
)

// Install registers the API group and adds types to a scheme
func Install(scheme *runtime.Scheme) {
utilruntime.Must(search.AddToScheme(scheme))
utilruntime.Must(v1beta1.AddToScheme(scheme))
utilruntime.Must(scheme.SetVersionPriority(v1beta1.SchemeGroupVersion))
}
30 changes: 30 additions & 0 deletions pkg/apis/search/install/roundtrip_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
Copyright The Karbour Authors.
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 install

import (
"testing"

searchfuzzer "github.com/KusionStack/karbour/pkg/apis/search/fuzzer"
"k8s.io/apimachinery/pkg/api/apitesting/roundtrip"
)

func TestRoundTripTypes(t *testing.T) {
roundtrip.RoundTripTestForAPIGroup(t, Install, searchfuzzer.Funcs)
// TODO: enable protobuf generation for the karbour-apiserver
// roundtrip.RoundTripProtobufTestForAPIGroup(t, Install, searchfuzzer.Funcs)
}
53 changes: 53 additions & 0 deletions pkg/apis/search/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
Copyright The Karbour Authors.
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 search

import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
)

// GroupName is the group name used in this package
const GroupName = "search.karbour.com"

// SchemeGroupVersion is group version used to register these objects
var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: runtime.APIVersionInternal}

// Kind takes an unqualified kind and returns back a Group qualified GroupKind
func Kind(kind string) schema.GroupKind {
return SchemeGroupVersion.WithKind(kind).GroupKind()
}

// Resource takes an unqualified resource and returns back a Group qualified GroupResource
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}

var (
// SchemeBuilder is the scheme builder with scheme init functions to run for this API package
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
// AddToScheme is a common registration function for mapping packaged scoped group & version keys to a scheme
AddToScheme = SchemeBuilder.AddToScheme
)

// Adds the list of known types to the given scheme.
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&Example{},
)
return nil
}
28 changes: 28 additions & 0 deletions pkg/apis/search/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
Copyright The Karbour Authors.
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 search

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

type Example struct {
metav1.TypeMeta
metav1.ObjectMeta
}
24 changes: 24 additions & 0 deletions pkg/apis/search/v1beta1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
Copyright The Karbour Authors.
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.
*/

// +k8s:openapi-gen=true
// +k8s:deepcopy-gen=package
// +k8s:conversion-gen=github.com/KusionStack/karbour/pkg/apis/search
// +k8s:defaulter-gen=TypeMeta
// +groupName=search.karbour.com

// Package v1beta1 Package v1beta1 is the v1beta1 version of the API.
package v1beta1 // import "github.com/KusionStack/karbour/pkg/apis/search/v1beta1"
61 changes: 61 additions & 0 deletions pkg/apis/search/v1beta1/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
Copyright The Karbour Authors.
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 v1beta1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
)

// GroupName holds the API group name.
const GroupName = "search.karbour.com"

// SchemeGroupVersion is group version used to register these objects
var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1beta1"}

var (
// SchemeBuilder allows to add this group to a scheme.
// TODO: move SchemeBuilder with zz_generated.deepcopy.go to k8s.io/api.
// localSchemeBuilder and AddToScheme will stay in k8s.io/kubernetes.
SchemeBuilder runtime.SchemeBuilder
localSchemeBuilder = &SchemeBuilder

// AddToScheme adds this group to a scheme.
AddToScheme = localSchemeBuilder.AddToScheme
)

func init() {
// We only register manually written functions here. The registration of the
// generated functions takes place in the generated files. The separation
// makes the code compile even when the generated files are missing.
localSchemeBuilder.Register(addKnownTypes)
}

// Adds the list of known types to the given scheme.
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&Example{},
)
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
return nil
}

// Resource takes an unqualified resource and returns a Group qualified GroupResource
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}
28 changes: 28 additions & 0 deletions pkg/apis/search/v1beta1/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
Copyright The Karbour Authors.
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 v1beta1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

type Example struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
}
Loading

0 comments on commit b5116e4

Please sign in to comment.