Skip to content

Commit

Permalink
subresource base64
Browse files Browse the repository at this point in the history
  • Loading branch information
phosae committed Jul 25, 2023
1 parent dd45a96 commit be8df3e
Show file tree
Hide file tree
Showing 21 changed files with 1,579 additions and 69 deletions.
6 changes: 6 additions & 0 deletions api-aggregation-lib/pkg/api/transformation/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**/

// +k8s:deepcopy-gen=package
// +groupName=transformation.zeng.dev

package transformation
16 changes: 16 additions & 0 deletions api-aggregation-lib/pkg/api/transformation/install/install.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package install

import (
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"

transformation "github.com/phosae/x-kubernetes/api-aggregation-lib/pkg/api/transformation"
transformationv1beta1 "github.com/phosae/x-kubernetes/api-aggregation-lib/pkg/api/transformation/v1beta1"
)

// Install registers the API group and adds types to a scheme
func Install(scheme *runtime.Scheme) {
utilruntime.Must(transformationv1beta1.AddToScheme(scheme))
utilruntime.Must(transformation.AddToScheme(scheme))
utilruntime.Must(scheme.SetVersionPriority(transformationv1beta1.SchemeGroupVersion))
}
36 changes: 36 additions & 0 deletions api-aggregation-lib/pkg/api/transformation/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package transformation

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

// GroupName is the group name use in this package
const GroupName = "transformation.zeng.dev"

// 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 a Group qualified GroupKind
func Kind(kind string) schema.GroupKind {
return SchemeGroupVersion.WithKind(kind).GroupKind()
}

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

var (
// SchemeBuilder points to a list of functions added to Scheme.
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
// AddToScheme applies all the stored functions to the scheme.
AddToScheme = SchemeBuilder.AddToScheme
)

func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&Base64{},
)
return nil
}
28 changes: 28 additions & 0 deletions api-aggregation-lib/pkg/api/transformation/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package transformation

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

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

// Base64 generates a base64 encoding for a specified Kubernetes object.
type Base64 struct {
metav1.TypeMeta
metav1.ObjectMeta

Spec Base64Spec
Status Base64Status
}

type Base64Spec struct {
// Path of the field to select in the specified object.
// defaults to . for the entire object
FieldPath string
}

type Base64Status struct {
// Output is the base64-encoded representation of
// the specified Kubernetes object or its subfield, as defined by the fieldPath.
Output string
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package v1beta1

func init() {
localSchemeBuilder.Register(RegisterDefaults)
}
9 changes: 9 additions & 0 deletions api-aggregation-lib/pkg/api/transformation/v1beta1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**/

// +k8s:conversion-gen=github.com/phosae/x-kubernetes/api-aggregation-lib/pkg/api/transformation
// +k8s:conversion-gen-external-types=github.com/phosae/x-kubernetes/api/transformation/v1beta1
// +groupName=transformation.zeng.dev
// +k8s:defaulter-gen=TypeMeta
// +k8s:defaulter-gen-input=github.com/phosae/x-kubernetes/api/transformation/v1beta1

package v1beta1
22 changes: 22 additions & 0 deletions api-aggregation-lib/pkg/api/transformation/v1beta1/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package v1beta1

import (
transformationv1beta1 "github.com/phosae/x-kubernetes/api/transformation/v1beta1"
"k8s.io/apimachinery/pkg/runtime/schema"
)

// GroupName is the group name use in this package
const GroupName = "transformation.zeng.dev"

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

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

var (
localSchemeBuilder = &transformationv1beta1.SchemeBuilder
AddToScheme = localSchemeBuilder.AddToScheme
)

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

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

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

10 changes: 6 additions & 4 deletions api-aggregation-lib/pkg/apiserver/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import (
clientrest "k8s.io/client-go/rest"

hello "github.com/phosae/x-kubernetes/api-aggregation-lib/pkg/api/hello.zeng.dev"
"github.com/phosae/x-kubernetes/api-aggregation-lib/pkg/api/hello.zeng.dev/install"
intallhello "github.com/phosae/x-kubernetes/api-aggregation-lib/pkg/api/hello.zeng.dev/install"
intalltransformation "github.com/phosae/x-kubernetes/api-aggregation-lib/pkg/api/transformation/install"
fooregistry "github.com/phosae/x-kubernetes/api-aggregation-lib/pkg/registry/hello.zeng.dev/foo"
)

Expand All @@ -40,7 +41,8 @@ var (
)

func init() {
install.Install(Scheme)
intallhello.Install(Scheme)
intalltransformation.Install(Scheme)

// we need to add the options to empty v1
metav1.AddToGroupVersion(Scheme, schema.GroupVersion{Group: "", Version: "v1"})
Expand Down Expand Up @@ -123,8 +125,8 @@ func (c completedConfig) New() (*HelloApiServer, error) {
return nil, err
}

v1storage := map[string]rest.Storage{"foos": restStorage.Foo}
v2storage := map[string]rest.Storage{"foos": restStorage.Foo, "foos/config": restStorage.Config, "foos/status": restStorage.Status}
v1storage := map[string]rest.Storage{"foos": restStorage.Foo, "foos/base64": restStorage.Base64}
v2storage := map[string]rest.Storage{"foos": restStorage.Foo, "foos/config": restStorage.Config, "foos/status": restStorage.Status, "foos/base64": restStorage.Base64}
apiGroupInfo.VersionedResourcesStorageMap["v1"] = v1storage
apiGroupInfo.VersionedResourcesStorageMap["v2"] = v2storage
}
Expand Down

0 comments on commit be8df3e

Please sign in to comment.