Skip to content

Commit

Permalink
Feat: upgrade go version and k8s api version
Browse files Browse the repository at this point in the history
  • Loading branch information
Somefive authored and yue9944882 committed Nov 2, 2022
1 parent 630e352 commit e0b65db
Show file tree
Hide file tree
Showing 25 changed files with 817 additions and 714 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: 1.18.2
go-version: 1.19.3
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- 'v*.*.*'
env:
# Common versions
GO_VERSION: '1.18'
GO_VERSION: '1.19'
GO_REQUIRED_MIN_VERSION: ''
GITHUB_REF: ${{ github.ref }}

Expand Down
3 changes: 0 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ linters:
disable-all: true
enable:
- bodyclose
- deadcode
- depguard
- dogsled
- dupl
Expand All @@ -35,13 +34,11 @@ linters:
- nakedret
- revive
- staticcheck
- structcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- varcheck
- whitespace

linters-settings:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fmt:
test -z $(go fmt ./tools/...)

lint:
(which golangci-lint || go get github.com/golangci/golangci-lint/cmd/golangci-lint)
(which golangci-lint || go install github.com/golangci/golangci-lint/cmd/golangci-lint)
$(GOBIN)/golangci-lint run ./...

test:
Expand Down
3 changes: 1 addition & 2 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ limitations under the License.

// Package apiserver_runtime contains libraries building Kubernetes style apiservers.
//
// Experimental
// # Experimental
//
// Note that this package is experimental and a work in progress. Do not rely on this project for production
// without first contacting the maintainers at kubebuilder@googlegroups.com.
//
package apiserver_runtime // nolint:stylecheck,revive
261 changes: 145 additions & 116 deletions go.mod

Large diffs are not rendered by default.

976 changes: 484 additions & 492 deletions go.sum

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions internal/example/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
genericregistry "k8s.io/apiserver/pkg/registry/generic"
regsitryrest "k8s.io/apiserver/pkg/registry/rest"

"sigs.k8s.io/apiserver-runtime/internal/example/v1alpha1"
"sigs.k8s.io/apiserver-runtime/pkg/builder"
"sigs.k8s.io/apiserver-runtime/pkg/builder/rest"
Expand Down Expand Up @@ -77,3 +78,5 @@ func (e ExampleHandler) Get(ctx context.Context, name string, options *v1.GetOpt
func (e ExampleHandler) New() runtime.Object {
return &v1alpha1.ExampleResource{}
}

func (e ExampleHandler) Destroy() {}
16 changes: 8 additions & 8 deletions pkg/builder/builder_misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import (

// WithOpenAPIDefinitions registers resource OpenAPI definitions generated by openapi-gen.
//
// export K8sAPIS=k8s.io/apimachinery/pkg/api/resource,\
// k8s.io/apimachinery/pkg/apis/meta/v1,\
// k8s.io/apimachinery/pkg/runtime,\
// k8s.io/apimachinery/pkg/version
// export MY_APIS=my-go-pkg/pkg/apis/my-group/my-version
// export OPENAPI=my-go-pkg/pkg/generated/openapi
// openapi-gen --input-dirs $K8SAPIS,$MY_APIS --output-package $OPENAPI \
// -O zz_generated.openapi --output-base ../../.. --go-header-file ./hack/boilerplate.go.txt
// export K8sAPIS=k8s.io/apimachinery/pkg/api/resource,\
// k8s.io/apimachinery/pkg/apis/meta/v1,\
// k8s.io/apimachinery/pkg/runtime,\
// k8s.io/apimachinery/pkg/version
// export MY_APIS=my-go-pkg/pkg/apis/my-group/my-version
// export OPENAPI=my-go-pkg/pkg/generated/openapi
// openapi-gen --input-dirs $K8SAPIS,$MY_APIS --output-package $OPENAPI \
// -O zz_generated.openapi --output-base ../../.. --go-header-file ./hack/boilerplate.go.txt
func (a *Server) WithOpenAPIDefinitions(
name, version string, openAPI openapicommon.GetOpenAPIDefinitions) *Server {
server.SetOpenAPIDefinitions(name, version, openAPI)
Expand Down
20 changes: 10 additions & 10 deletions pkg/builder/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ limitations under the License.

// Package builder contains a builder for creating a new Kubernetes apiserver.
//
// API Extension Servers
// # API Extension Servers
//
// API extension servers and apiserver aggregation are techniques for extending the Kubernetes API surface
// without using CRDs. Rather than registering a resource type as a CRD stored by the apiserver in etcd, apiserver
// aggregation registers REST endpoints provided by the extension server, and requests are proxied by the main
// control-plane apiserver to the extension apiserver.
//
// Use Cases
// # Use Cases
//
// Following are use cases where one may consider using an extension API server rather than CRDs for implementing
// an extension resource type.
Expand All @@ -34,32 +34,32 @@ limitations under the License.
//
// * Using a separate etcd instance for the extension types
//
// Registering Types
// # Registering Types
//
// New resource types may be registered with the API server by implementing the go struct for the type under
// YOUR_MODULE/pkg/apis/YOUR_GROUP/VERSION/types.go and then calling WithResource.
// You will need to generate deepcopy and openapi go code for your types to be registered.
//
// Install the code generators (from your module):
//
// $ go get sigs.k8s.io/apiserver-runtime/tools/apiserver-runtime-gen
// $ apiserver-runtime-gen --install-generators
// $ go get sigs.k8s.io/apiserver-runtime/tools/apiserver-runtime-gen
// $ apiserver-runtime-gen --install-generators
//
// Add the code generation tag to you main package:
//
// //go:generate apiserver-runtime-gen
// package main
// //go:generate apiserver-runtime-gen
// package main
//
// Run the code generation after having defined your types:
//
// $ go generate ./...
// $ go generate ./...
//
// To also generate clients, provide the -g option to apiserver-runtime-gen for the client, lister and informer
// generators.
//
// $ apiserver-runtime-gen -g client-gen -g deepcopy-gen -g informer-gen -g lister-gen -g openapi-gen
// $ apiserver-runtime-gen -g client-gen -g deepcopy-gen -g informer-gen -g lister-gen -g openapi-gen
//
// Implementing Type Specific Logic
// # Implementing Type Specific Logic
//
// * How an object is stored may be customized by either 1) implementing interfaces defined in
// pkg/builder/resource/resourcestrategy or 2) providing a Strategy when registering the type with the builder.
Expand Down
5 changes: 5 additions & 0 deletions pkg/builder/rest/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apiserver/pkg/registry/generic"
"k8s.io/apiserver/pkg/registry/rest"

"sigs.k8s.io/apiserver-runtime/internal/sample-apiserver/pkg/apiserver"
contextutil "sigs.k8s.io/apiserver-runtime/pkg/util/context"
)
Expand Down Expand Up @@ -82,6 +83,8 @@ func (p parentPlumbedStorageGetterProvider) New() runtime.Object {
return p.parentStorage.New()
}

func (p parentPlumbedStorageGetterProvider) Destroy() {}

func (p parentPlumbedStorageGetterProvider) Get(ctx context.Context, name string, options *metav1.GetOptions) (runtime.Object, error) {
return p.delegate.Get(contextutil.WithParentStorage(ctx, p.parentStorage), name, options)
}
Expand All @@ -99,6 +102,8 @@ func (p parentPlumbedStorageGetterUpdaterProvider) New() runtime.Object {
return p.parentStorage.New()
}

func (p parentPlumbedStorageGetterUpdaterProvider) Destroy() {}

func (p parentPlumbedStorageGetterUpdaterProvider) Get(ctx context.Context, name string, options *metav1.GetOptions) (runtime.Object, error) {
return p.getter.Get(contextutil.WithParentStorage(ctx, p.parentStorage), name, options)
}
Expand Down
15 changes: 15 additions & 0 deletions pkg/builder/storage_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"k8s.io/apiserver/pkg/registry/generic/registry"
registryrest "k8s.io/apiserver/pkg/registry/rest"
"k8s.io/klog/v2"

"sigs.k8s.io/apiserver-runtime/pkg/builder/resource"
"sigs.k8s.io/apiserver-runtime/pkg/builder/resource/util"
"sigs.k8s.io/apiserver-runtime/pkg/builder/rest"
Expand Down Expand Up @@ -149,6 +150,10 @@ func (s *statusSubResourceStorage) New() runtime.Object {
return s.store.New()
}

func (s *statusSubResourceStorage) Destroy() {
s.store.Destroy()
}

func (s *statusSubResourceStorage) Update(ctx context.Context,
name string,
objInfo registryrest.UpdatedObjectInfo,
Expand Down Expand Up @@ -193,6 +198,10 @@ func (c *commonSubResourceStorage) New() runtime.Object {
return c.subResourceConstructor.New()
}

func (c *commonSubResourceStorage) Destroy() {
c.subResourceConstructor.Destroy()
}

func (c *commonSubResourceStorage) Get(ctx context.Context, name string, options *v1.GetOptions) (runtime.Object, error) {
return c.subResourceGetter.Get(
contextutil.WithParentStorage(ctx, c.parentStorage),
Expand Down Expand Up @@ -232,6 +241,10 @@ func (c *connectorSubResourceStorage) New() runtime.Object {
return c.subResourceConstructor.New()
}

func (c *connectorSubResourceStorage) Destroy() {
c.subResourceConstructor.Destroy()
}

func (c *connectorSubResourceStorage) Connect(ctx context.Context, id string, options runtime.Object, r registryrest.Responder) (http.Handler, error) {
return c.subResourceConnector.Connect(
contextutil.WithParentStorage(ctx, c.parentStorage),
Expand Down Expand Up @@ -267,6 +280,8 @@ func (s *scaleSubResourceStorage) New() runtime.Object {
return &autoscalingv1.Scale{}
}

func (s *scaleSubResourceStorage) Destroy() {}

func (s *scaleSubResourceStorage) Get(ctx context.Context, name string, options *v1.GetOptions) (runtime.Object, error) {
parentObj, err := s.parentStorageGetter.Get(
contextutil.WithParentStorage(ctx, s.parentStorage),
Expand Down
29 changes: 15 additions & 14 deletions pkg/experimental/storage/filepath/jsonfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,26 @@ import (
// - For namespaced-scoped resources: the resource will be written under the root-path in
// the following structure:
//
// -- (root-path) --- /namespace1/ --- resource1
// | |
// | --- resource2
// |
// --- /namespace2/ --- resource3
// -- (root-path) --- /namespace1/ --- resource1
// | |
// | --- resource2
// |
// --- /namespace2/ --- resource3
//
// - For cluster-scoped resources, there will be no mid-layer folders for namespaces:
//
// -- (root-path) --- resource1
// |
// --- resource2
// |
// --- resource3
// -- (root-path) --- resource1
// |
// --- resource2
// |
// --- resource3
//
// An example of storing example resource to local filepath will be:
//
// builder.APIServer.
// WithResourceAndHandler(&v1alpha1.ExampleResource{},
// jsonfile.NewJsonFileStorageProvider(&v1alpha1.ExampleResource{}, /*the root file-path*/ "data")).
// Build()
// builder.APIServer.
// WithResourceAndHandler(&v1alpha1.ExampleResource{},
// jsonfile.NewJsonFileStorageProvider(&v1alpha1.ExampleResource{}, /*the root file-path*/ "data")).
// Build()
func NewJSONFilepathStorageProvider(obj resource.Object, rootPath string) builderrest.ResourceHandlerProvider {
return func(scheme *runtime.Scheme, getter generic.RESTOptionsGetter) (rest.Storage, error) {
gr := obj.GetGroupVersionResource().GroupResource()
Expand Down
7 changes: 4 additions & 3 deletions pkg/experimental/storage/filepath/jsonfile_rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"reflect"
Expand Down Expand Up @@ -85,6 +84,8 @@ func (f *filepathREST) New() runtime.Object {
return f.newFunc()
}

func (f *filepathREST) Destroy() {}

func (f *filepathREST) NewList() runtime.Object {
return f.newListFunc()
}
Expand Down Expand Up @@ -306,11 +307,11 @@ func write(encoder runtime.Encoder, filepath string, obj runtime.Object) error {
if err := encoder.Encode(obj, buf); err != nil {
return err
}
return ioutil.WriteFile(filepath, buf.Bytes(), 0600)
return os.WriteFile(filepath, buf.Bytes(), 0600)
}

func read(decoder runtime.Decoder, path string, newFunc func() runtime.Object) (runtime.Object, error) {
content, err := ioutil.ReadFile(filepath.Clean(path))
content, err := os.ReadFile(filepath.Clean(path))
if err != nil {
return nil, err
}
Expand Down
20 changes: 10 additions & 10 deletions pkg/experimental/storage/mysql/kine.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ import (
genericregistry "k8s.io/apiserver/pkg/registry/generic/registry"
"k8s.io/apiserver/pkg/storage/storagebackend"
"k8s.io/apiserver/pkg/util/flowcontrol/request"

builderrest "sigs.k8s.io/apiserver-runtime/pkg/builder/rest"
)

// NewMysqlStorageProvider replaces underlying persistent layer (which by default is etcd) w/ MySQL.
// An example of storaing example resource to Mysql will be:
//
// builder.APIServer.
// WithResourceAndStorage(&v1alpha1.ExampleResource{}, mysql.NewMysqlStorageProvider(
// "", // mysql host name e.g. "127.0.0.1"
// 0, // mysql password e.g. 3306
// "", // mysql username e.g. "mysql"
// "", // mysql password e.g. "password"
// "", // mysql database name e.g. "mydb"
// )).Build()
//
// builder.APIServer.
// WithResourceAndStorage(&v1alpha1.ExampleResource{}, mysql.NewMysqlStorageProvider(
// "", // mysql host name e.g. "127.0.0.1"
// 0, // mysql password e.g. 3306
// "", // mysql username e.g. "mysql"
// "", // mysql password e.g. "password"
// "", // mysql database name e.g. "mydb"
// )).Build()
func NewMysqlStorageProvider(host string, port int32, username, password, database string) builderrest.StoreFn {
dsn := fmt.Sprintf("mysql://%s:%s@tcp(%s:%d)/%s",
username,
Expand Down Expand Up @@ -70,7 +70,7 @@ func (g *kineProxiedRESTOptionsGetter) GetRESTOptions(resource schema.GroupResou
EnableGarbageCollection: true,
DeleteCollectionWorkers: 1,
CountMetricPollPeriod: time.Minute,
StorageObjectCountTracker: request.NewStorageObjectCountTracker(context.Background().Done()),
StorageObjectCountTracker: request.NewStorageObjectCountTracker(),
StorageConfig: &storagebackend.ConfigForResource{
GroupResource: resource,
Config: storagebackend.Config{
Expand Down
2 changes: 0 additions & 2 deletions sample/pkg/apis/sample/v1alpha1/fortune.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ func (f Fortune) convertToTable(_ context.Context, tableOptions runtime.Object)
return nil, err
}
c.ResourceVersion = f.GetResourceVersion()
c.SelfLink = f.GetSelfLink()
c.setOptions(tableOptions)
return &c.Table, nil
}
Expand All @@ -72,7 +71,6 @@ func (f FortuneList) convertToTable(_ context.Context, tableOptions runtime.Obje
}
c.setOptions(tableOptions)
c.ResourceVersion = f.GetResourceVersion()
c.SelfLink = f.GetSelfLink()
c.Continue = f.GetContinue()
c.RemainingItemCount = f.GetRemainingItemCount()
return &c.Table, nil
Expand Down
Loading

0 comments on commit e0b65db

Please sign in to comment.