Skip to content

Commit

Permalink
api: add hello.zeng.dev/v2
Browse files Browse the repository at this point in the history
  • Loading branch information
phosae committed Jun 8, 2023
1 parent 9ef420d commit 8cc7165
Show file tree
Hide file tree
Showing 11 changed files with 193 additions and 5 deletions.
37 changes: 37 additions & 0 deletions api/api-rules/violation_exceptions.list
@@ -0,0 +1,37 @@
API rule violation: list_type_missing,github.com/phosae/x-kubernetes/api/hello.zeng.dev/v2,FooStatus,Conditions
API rule violation: list_type_missing,k8s.io/apimachinery/pkg/apis/meta/v1,APIGroup,ServerAddressByClientCIDRs
API rule violation: list_type_missing,k8s.io/apimachinery/pkg/apis/meta/v1,APIGroup,Versions
API rule violation: list_type_missing,k8s.io/apimachinery/pkg/apis/meta/v1,APIGroupList,Groups
API rule violation: list_type_missing,k8s.io/apimachinery/pkg/apis/meta/v1,APIResource,Categories
API rule violation: list_type_missing,k8s.io/apimachinery/pkg/apis/meta/v1,APIResource,ShortNames
API rule violation: list_type_missing,k8s.io/apimachinery/pkg/apis/meta/v1,APIResourceList,APIResources
API rule violation: list_type_missing,k8s.io/apimachinery/pkg/apis/meta/v1,APIVersions,ServerAddressByClientCIDRs
API rule violation: list_type_missing,k8s.io/apimachinery/pkg/apis/meta/v1,APIVersions,Versions
API rule violation: list_type_missing,k8s.io/apimachinery/pkg/apis/meta/v1,ApplyOptions,DryRun
API rule violation: list_type_missing,k8s.io/apimachinery/pkg/apis/meta/v1,CreateOptions,DryRun
API rule violation: list_type_missing,k8s.io/apimachinery/pkg/apis/meta/v1,DeleteOptions,DryRun
API rule violation: list_type_missing,k8s.io/apimachinery/pkg/apis/meta/v1,FieldsV1,Raw
API rule violation: list_type_missing,k8s.io/apimachinery/pkg/apis/meta/v1,LabelSelector,MatchExpressions
API rule violation: list_type_missing,k8s.io/apimachinery/pkg/apis/meta/v1,LabelSelectorRequirement,Values
API rule violation: list_type_missing,k8s.io/apimachinery/pkg/apis/meta/v1,ObjectMeta,Finalizers
API rule violation: list_type_missing,k8s.io/apimachinery/pkg/apis/meta/v1,ObjectMeta,ManagedFields
API rule violation: list_type_missing,k8s.io/apimachinery/pkg/apis/meta/v1,ObjectMeta,OwnerReferences
API rule violation: list_type_missing,k8s.io/apimachinery/pkg/apis/meta/v1,PatchOptions,DryRun
API rule violation: list_type_missing,k8s.io/apimachinery/pkg/apis/meta/v1,RootPaths,Paths
API rule violation: list_type_missing,k8s.io/apimachinery/pkg/apis/meta/v1,StatusDetails,Causes
API rule violation: list_type_missing,k8s.io/apimachinery/pkg/apis/meta/v1,Table,ColumnDefinitions
API rule violation: list_type_missing,k8s.io/apimachinery/pkg/apis/meta/v1,Table,Rows
API rule violation: list_type_missing,k8s.io/apimachinery/pkg/apis/meta/v1,TableRow,Cells
API rule violation: list_type_missing,k8s.io/apimachinery/pkg/apis/meta/v1,TableRow,Conditions
API rule violation: list_type_missing,k8s.io/apimachinery/pkg/apis/meta/v1,UpdateOptions,DryRun
API rule violation: list_type_missing,k8s.io/apimachinery/pkg/runtime,RawExtension,Raw
API rule violation: list_type_missing,k8s.io/apimachinery/pkg/runtime,Unknown,Raw
API rule violation: names_match,k8s.io/apimachinery/pkg/apis/meta/v1,APIResourceList,APIResources
API rule violation: names_match,k8s.io/apimachinery/pkg/apis/meta/v1,Duration,Duration
API rule violation: names_match,k8s.io/apimachinery/pkg/apis/meta/v1,InternalEvent,Object
API rule violation: names_match,k8s.io/apimachinery/pkg/apis/meta/v1,InternalEvent,Type
API rule violation: names_match,k8s.io/apimachinery/pkg/apis/meta/v1,MicroTime,Time
API rule violation: names_match,k8s.io/apimachinery/pkg/apis/meta/v1,StatusCause,Type
API rule violation: names_match,k8s.io/apimachinery/pkg/apis/meta/v1,Time,Time
API rule violation: names_match,k8s.io/apimachinery/pkg/runtime,Unknown,ContentEncoding
API rule violation: names_match,k8s.io/apimachinery/pkg/runtime,Unknown,ContentType
22 changes: 21 additions & 1 deletion api/artifacts/crd/hello.zeng.dev_foos.yaml
Expand Up @@ -14,7 +14,7 @@ spec:
versions:
- name: v1
served: true
storage: true
storage: false
additionalPrinterColumns:
- name: age
jsonPath: .metadata.creationTimestamp
Expand Down Expand Up @@ -51,3 +51,23 @@ spec:
msg1:
description: Msg1 provides some verbose information
type: string
- name: v2
served: true
storage: true
additionalPrinterColumns:
- name: status
jsonPath: .status.phase
type: string
- name: age
jsonPath: .metadata.creationTimestamp
type: date
- name: message
jsonPath: .spec.config.msg
type: string
priority: 1
- name: message1
jsonPath: .spec.config.msg1
type: string
priority: 1
schema:
openAPIV3Schema: {}
2 changes: 1 addition & 1 deletion api/go.mod
Expand Up @@ -4,6 +4,7 @@ go 1.20

require (
github.com/gogo/protobuf v1.3.2
k8s.io/api v0.27.1
k8s.io/apimachinery v0.27.1
k8s.io/client-go v0.27.1
k8s.io/kube-openapi v0.0.0-20230308215209-15aac26d736a
Expand Down Expand Up @@ -41,7 +42,6 @@ require (
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.27.1 // indirect
k8s.io/klog/v2 v2.100.1 // indirect
k8s.io/utils v0.0.0-20230209194617-a36077c30491 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
Expand Down
6 changes: 4 additions & 2 deletions api/hack/update-codegen-docker.sh
Expand Up @@ -3,14 +3,16 @@ set -eu
PROJECT_PACKAGE=github.com/phosae/x-kubernetes/api

docker run -it --rm -u root \
-v $(cd ../ && pwd):/go/src/github.com/phosae/x-kubernetes\
-v ${PWD}/..:/go/src/github.com/phosae/x-kubernetes\
-v ${PWD}/hack/custom-boilerplate.go.txt:/tmp/fake-boilerplate.txt \
-v ${PWD}/api-rules/violation_exceptions.list:/tmp/validation-exceptions.list \
-e GOPROXY="https://goproxy.cn"\
-e PROJECT_PACKAGE=${PROJECT_PACKAGE} \
-e CLIENT_GENERATOR_OUT=${PROJECT_PACKAGE}/generated \
-e OPENAPI_GENERATOR_OUT=${PROJECT_PACKAGE}/generated \
-e APIS_ROOT=${PROJECT_PACKAGE} \
-e GENERATION_TARGETS="helpers,client,openapi" \
-e OPENAPI_VIOLATION_EXCEPTIONS="/tmp/validation-exceptions.list" \
-e WITH_APPLYCONFIG="true" \
-e WITH_WATCH="" \
zengxu/kube-code-generator:v1.28.0-alpha.1
Expand All @@ -21,4 +23,4 @@ docker run -it --rm -u root \
-v ${PWD}:/go/src/${PROJECT_PACKAGE}\
-w /go/src/${PROJECT_PACKAGE}\
zengxu/kube-code-generator:v1.28.0-alpha.1\
update-generated-protobuf.sh github.com/phosae/x-kubernetes/api/hello.zeng.dev/v1
update-generated-protobuf.sh github.com/phosae/x-kubernetes/api/hello.zeng.dev/v1,github.com/phosae/x-kubernetes/api/hello.zeng.dev/v2
2 changes: 1 addition & 1 deletion api/hack/update-crd-docker.sh
Expand Up @@ -13,5 +13,5 @@ docker run -it --rm -u root \
-e CRD_FLAG="schemapatch:manifests=./api/artifacts/crd"\
-e CRD_TYPES_PATH="/src/api"\
-e CRD_OUT_PATH="/src/api/artifacts/crd"\
zengxu/kube-code-generator:v1.27.1-pb\
zengxu/kube-code-generator:v1.28.0-alpha.1\
update-crd.sh
1 change: 1 addition & 0 deletions api/hello.zeng.dev/install.go
Expand Up @@ -7,6 +7,7 @@ import (
)

// Install registers the API group and adds types to a scheme
// DEPRECATED: implementations such as apiserver should install APIs with their own hub type, conversion func, default funcs, etc
func Install(scheme *runtime.Scheme) {
utilruntime.Must(AddToScheme(scheme))
utilruntime.Must(v1.AddToScheme(scheme))
Expand Down
1 change: 1 addition & 0 deletions api/hello.zeng.dev/register.go
@@ -1,3 +1,4 @@
// DEPRECATED: implementations such as apiserver should provide their own hub packge
package hello_zeng_dev

import (
Expand Down
3 changes: 3 additions & 0 deletions api/hello.zeng.dev/v1/register.go
@@ -1,6 +1,7 @@
package v1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
)
Expand Down Expand Up @@ -28,6 +29,8 @@ func addKnownTypes(scheme *runtime.Scheme) error {
&Foo{},
&FooList{},
)
// add common meta types (i.e WatchEvent, ListOptions, ...) to the SchemeGroupVersion
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
return nil
}

Expand Down
9 changes: 9 additions & 0 deletions api/hello.zeng.dev/v2/doc.go
@@ -0,0 +1,9 @@
/*
*/

// +k8s:openapi-gen=true
// +k8s:deepcopy-gen=package
// +k8s:protobuf-gen=package
// +groupName=hello.zeng.dev

package v2
40 changes: 40 additions & 0 deletions api/hello.zeng.dev/v2/register.go
@@ -0,0 +1,40 @@
package v2

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

const GroupName = "hello.zeng.dev"

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

var (
SchemeBuilder runtime.SchemeBuilder
localSchemeBuilder = &SchemeBuilder

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

func init() {
localSchemeBuilder.Register(addKnownTypes)
}

// Adds the list of known types to the given scheme.
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&Foo{},
&FooList{},
)
// add common meta types (i.e WatchEvent, ListOptions, ...) to the SchemeGroupVersion
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()
}
75 changes: 75 additions & 0 deletions api/hello.zeng.dev/v2/types.go
@@ -0,0 +1,75 @@
package v2

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

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

type Foo struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec FooSpec `json:"spec"`
Status FooStatus `json:"status,omitempty"`
}

type FooSpec struct {
// Container image that the container is running to do our foo work
Image string `json:"image"`
// Config is the configuration used by foo container
Config FooConfig `json:"config"`
}

type FooConfig struct {
// Msg says hello world!
Msg string `json:"msg"`
// Msg1 provides some verbose information
// +optional
Msg1 string `json:"msg1,omitempty"`
}

// FooPhase is a label for the condition of a foo at the current time.
type FooPhase string

const (
// FooPhaseProcessing means the pod has been accepted by the controllers, but one or more desire has not been synchorinzed
FooPhaseProcessing FooPhase = "Processing"
// FooPhaseReady means all conditions of foo have been meant
FooPhaseReady FooPhase = "Ready"
)

type FooStatus struct {
// The phase of a Foo is a simple, high-level summary of where the Foo is in its lifecycle
// +optional
Phase FooPhase `json:"phase,omitempty"`

// Represents the latest available observations of a foo's current state
// +optional
// +patchMergeKey=type
// +patchStrategy=merge
Conditions []FooCondition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"`
}

type FooConditionType string

const (
FooConditionTypeWorker FooConditionType = "Worker"
FooConditionTypeConfig FooConditionType = "Config"
)

type FooCondition struct {
Type FooConditionType `json:"type"`
Status corev1.ConditionStatus `json:"status"`
}

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

type FooList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`

Items []Foo `json:"items"`
}

0 comments on commit 8cc7165

Please sign in to comment.