Skip to content

Commit

Permalink
Redefine Migrate CRD.
Browse files Browse the repository at this point in the history
  • Loading branch information
yongzhi.yang committed May 14, 2019
1 parent 2fcc85f commit d3e01aa
Show file tree
Hide file tree
Showing 39 changed files with 118 additions and 2,069 deletions.
4 changes: 2 additions & 2 deletions artifacts/examples/crd.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: foos.migrate.dmall.com
name: foos.example.dmall.com
spec:
group: migrate.dmall.com
group: example.dmall.com
version: v1
names:
kind: Foo
Expand Down
2 changes: 1 addition & 1 deletion artifacts/examples/example-foo.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: migrate.dmall.com/v1
apiVersion: example.dmall.com/v1
kind: Foo
metadata:
name: example-foo
Expand Down
8 changes: 4 additions & 4 deletions controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ import (
"k8s.io/client-go/util/workqueue"
"k8s.io/klog"

samplev1alpha1 "github.com/yangyongzhi/sym-operator/pkg/apis/migrate/v1"
samplev1alpha1 "github.com/yangyongzhi/sym-operator/pkg/apis/example/v1"
clientset "github.com/yangyongzhi/sym-operator/pkg/client/clientset/versioned"
samplescheme "github.com/yangyongzhi/sym-operator/pkg/client/clientset/versioned/scheme"
informers "github.com/yangyongzhi/sym-operator/pkg/client/informers/externalversions/migrate/v1"
listers "github.com/yangyongzhi/sym-operator/pkg/client/listers/migrate/v1"
informers "github.com/yangyongzhi/sym-operator/pkg/client/informers/externalversions/example/v1"
listers "github.com/yangyongzhi/sym-operator/pkg/client/listers/example/v1"
)

const controllerAgentName = "sample-controller"
Expand Down Expand Up @@ -329,7 +329,7 @@ func (c *Controller) updateFooStatus(foo *samplev1alpha1.Foo, deployment *appsv1
// we must use Update instead of UpdateStatus to update the Status block of the Foo resource.
// UpdateStatus will not allow changes to the Spec of the resource,
// which is ideal for ensuring nothing other than resource status has been updated.
_, err := c.sampleclientset.MigrateV1().Foos(foo.Namespace).Update(fooCopy)
_, err := c.sampleclientset.ExampleV1().Foos(foo.Namespace).Update(fooCopy)
return err
}

Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ module github.com/yangyongzhi/sym-operator
go 1.12

require (
k8s.io/api v0.0.0-20190425012535-181e1f9c52c1
k8s.io/apimachinery v0.0.0-20190425132440-17f84483f500
k8s.io/api v0.0.0-20190430012547-97d6bb8ea5f4
k8s.io/apiextensions-apiserver v0.0.0-20190502093314-7526e4c489ad
k8s.io/apimachinery v0.0.0-20190502092502-a44ef629a3c9
k8s.io/client-go v0.0.0-20190425172711-65184652c889
k8s.io/code-generator v0.0.0-20190419212335-ff26e7842f9d
k8s.io/klog v0.3.0
Expand Down
91 changes: 89 additions & 2 deletions go.sum

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions hack/codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ PACKAGE_NAME=github.com/yangyongzhi/sym-operator
REPO_ROOT="$GOPATH/src/$PACKAGE_NAME"
DOCKER_REPO_ROOT="/go/src/$PACKAGE_NAME"
DOCKER_CODEGEN_PKG="/go/src/k8s.io/code-generator"
apiGroups=(migrate/v1)
apiGroups=(example/v1 devops/v1)

pushd $REPO_ROOT

## Generate ugorji stuff
rm "$REPO_ROOT"/pkg/apis/migrate/v1/*.deepcopy.go
rm "$REPO_ROOT"/pkg/apis/example/v1/*.deepcopy.go



Expand All @@ -23,7 +24,7 @@ docker run --rm -ti -u $(id -u):$(id -g) \
hub.tencentyun.com/xkcp0324/gengo:release-1.12 "$DOCKER_CODEGEN_PKG"/generate-groups.sh all \
$PACKAGE_NAME/pkg/client \
$PACKAGE_NAME/pkg/apis \
"migrate:v1" \
"example:v1 devops:v1" \
--go-header-file "$DOCKER_REPO_ROOT/hack/boilerplate.go.txt"

popd
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func main() {

controller := NewController(kubeClient, exampleClient,
kubeInformerFactory.Apps().V1().Deployments(),
exampleInformerFactory.Migrate().V1().Foos())
exampleInformerFactory.Example().V1().Foos())

// notice that there is no need to run Start methods in a separate goroutine. (i.e. go kubeInformerFactory.Start(stopCh)
// Start method is non-blocking and runs all registered informers in a dedicated goroutine.
Expand Down
12 changes: 12 additions & 0 deletions pkg/apis/example/v1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Package v1 is the v1 version of the API.

// +k8s:deepcopy-gen=package,register
// +groupName=example.dmall.com
package v1

const (
// GroupName is the group name use in this package
GroupName = "example.dmall.com"
// ResourceVersion represent the resource version
ResourceVersion = "v1"
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,12 @@ import (
)

const (
// GroupName is the group name use in this package
GroupName = "migrate.dmall.com"
// ResourcePlural is the id to indentify pluarals
ResourcePlural = "migrates"
ResourcePlural = "foos"
// ResourceSingular represents the id for identify singular resource
ResourceSingular = "migrate"
ResourceSingular = "foo"
// ResourceKind represent the resource kind
ResourceKind = "Migrate"
// ResourceVersion represent the resource version
ResourceVersion = "v1"
ResourceKind = "Foo"
)

// SchemeGroupVersion is group version used to register these objects
Expand Down Expand Up @@ -45,8 +41,6 @@ func init() {
// Adds the list of known types to api.Scheme.
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&Migrate{},
&MigrateList{},
&Foo{},
&FooList{},
)
Expand Down
File renamed without changes.
5 changes: 0 additions & 5 deletions pkg/apis/migrate/v1/doc.go

This file was deleted.

68 changes: 0 additions & 68 deletions pkg/apis/migrate/v1/types.go

This file was deleted.

Loading

0 comments on commit d3e01aa

Please sign in to comment.