-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- kubebuilder init --domain k8s.io - kubebuilder create resoure --group samplecontroller --version v1alpha1 --kind Foo
- Loading branch information
Showing
40 changed files
with
2,343 additions
and
0 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
samples/full/controller/src/samplecontroller/cmd/controller-manager/main.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
Copyright 2017 The Kubernetes 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 main | ||
|
||
import ( | ||
"flag" | ||
"log" | ||
|
||
// Import auth/gcp to connect to GKE clusters remotely | ||
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp" | ||
|
||
configlib "github.com/kubernetes-sigs/kubebuilder/pkg/config" | ||
"github.com/kubernetes-sigs/kubebuilder/pkg/inject/run" | ||
"github.com/kubernetes-sigs/kubebuilder/pkg/install" | ||
"github.com/kubernetes-sigs/kubebuilder/pkg/signals" | ||
extensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1" | ||
|
||
"samplecontroller/pkg/inject" | ||
"samplecontroller/pkg/inject/args" | ||
) | ||
|
||
var installCRDs = flag.Bool("install-crds", true, "install the CRDs used by the controller as part of startup") | ||
|
||
// Controller-manager main. | ||
func main() { | ||
flag.Parse() | ||
|
||
stopCh := signals.SetupSignalHandler() | ||
|
||
config := configlib.GetConfigOrDie() | ||
|
||
if *installCRDs { | ||
if err := install.NewInstaller(config).Install(&InstallStrategy{crds: inject.Injector.CRDs}); err != nil { | ||
log.Fatalf("Could not create CRDs: %v", err) | ||
} | ||
} | ||
|
||
// Start the controllers | ||
if err := inject.RunAll(run.RunArguments{Stop: stopCh}, args.CreateInjectArgs(config)); err != nil { | ||
log.Fatalf("%v", err) | ||
} | ||
} | ||
|
||
type InstallStrategy struct { | ||
install.EmptyInstallStrategy | ||
crds []*extensionsv1beta1.CustomResourceDefinition | ||
} | ||
|
||
func (s *InstallStrategy) GetCRDs() []*extensionsv1beta1.CustomResourceDefinition { | ||
return s.crds | ||
} |
23 changes: 23 additions & 0 deletions
23
samples/full/controller/src/samplecontroller/pkg/apis/doc.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
/* | ||
Copyright 2017 The Kubernetes 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. | ||
*/ | ||
|
||
|
||
// | ||
// +domain=k8s.io | ||
|
||
package apis | ||
|
24 changes: 24 additions & 0 deletions
24
samples/full/controller/src/samplecontroller/pkg/apis/samplecontroller/doc.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
/* | ||
Copyright 2017 The Kubernetes 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,register | ||
// +groupName=samplecontroller.k8s.io | ||
|
||
// Package api is the internal version of the API. | ||
package samplecontroller |
28 changes: 28 additions & 0 deletions
28
samples/full/controller/src/samplecontroller/pkg/apis/samplecontroller/v1alpha1/doc.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
/* | ||
Copyright 2017 The Kubernetes 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. | ||
*/ | ||
|
||
|
||
// Api versions allow the api contract for a resource to be changed while keeping | ||
// backward compatibility by support multiple concurrent versions | ||
// of the same resource | ||
|
||
// +k8s:openapi-gen=true | ||
// +k8s:deepcopy-gen=package,register | ||
// +k8s:conversion-gen=samplecontroller/pkg/apis/samplecontroller | ||
// +k8s:defaulter-gen=TypeMeta | ||
// +groupName=samplecontroller.k8s.io | ||
package v1alpha1 // import "samplecontroller/pkg/apis/samplecontroller/v1alpha1" |
52 changes: 52 additions & 0 deletions
52
samples/full/controller/src/samplecontroller/pkg/apis/samplecontroller/v1alpha1/foo_types.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
|
||
/* | ||
Copyright 2017 The Kubernetes 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 v1alpha1 | ||
|
||
import ( | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// EDIT THIS FILE! | ||
// Created by "kubebuilder create resource" for you to implement the Foo resource schema definition | ||
// as a go struct. | ||
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. | ||
|
||
// FooSpec defines the desired state of Foo | ||
type FooSpec struct { | ||
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster | ||
} | ||
|
||
// FooStatus defines the observed state of Foo | ||
type FooStatus struct { | ||
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster | ||
} | ||
|
||
// +genclient | ||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object | ||
|
||
// Foo | ||
// +k8s:openapi-gen=true | ||
// +resource:path=foos | ||
type Foo struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
||
Spec FooSpec `json:"spec,omitempty"` | ||
Status FooStatus `json:"status,omitempty"` | ||
} |
85 changes: 85 additions & 0 deletions
85
...full/controller/src/samplecontroller/pkg/apis/samplecontroller/v1alpha1/foo_types_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
|
||
/* | ||
Copyright 2017 The Kubernetes 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 v1alpha1_test | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
. "samplecontroller/pkg/apis/samplecontroller/v1alpha1" | ||
. "samplecontroller/pkg/client/clientset/versioned/typed/samplecontroller/v1alpha1" | ||
) | ||
|
||
// EDIT THIS FILE! | ||
// Created by "kubebuilder create resource" for you to implement the Foo resource tests | ||
|
||
var _ = Describe("Foo", func() { | ||
var instance Foo | ||
var expected Foo | ||
var client FooInterface | ||
|
||
BeforeEach(func() { | ||
instance = Foo{} | ||
instance.Name = "instance-1" | ||
|
||
expected = instance | ||
}) | ||
|
||
AfterEach(func() { | ||
client.Delete(instance.Name, &metav1.DeleteOptions{}) | ||
}) | ||
|
||
// INSERT YOUR CODE HERE - add more "Describe" tests | ||
|
||
// Automatically created storage tests | ||
Describe("when sending a storage request", func() { | ||
Context("for a valid config", func() { | ||
It("should provide CRUD access to the object", func() { | ||
client = cs.SamplecontrollerV1alpha1().Foos("default") | ||
|
||
By("returning success from the create request") | ||
actual, err := client.Create(&instance) | ||
Expect(err).ShouldNot(HaveOccurred()) | ||
|
||
By("defaulting the expected fields") | ||
Expect(actual.Spec).To(Equal(expected.Spec)) | ||
|
||
By("returning the item for list requests") | ||
result, err := client.List(metav1.ListOptions{}) | ||
Expect(err).ShouldNot(HaveOccurred()) | ||
Expect(result.Items).To(HaveLen(1)) | ||
Expect(result.Items[0].Spec).To(Equal(expected.Spec)) | ||
|
||
By("returning the item for get requests") | ||
actual, err = client.Get(instance.Name, metav1.GetOptions{}) | ||
Expect(err).ShouldNot(HaveOccurred()) | ||
Expect(actual.Spec).To(Equal(expected.Spec)) | ||
|
||
By("deleting the item for delete requests") | ||
err = client.Delete(instance.Name, &metav1.DeleteOptions{}) | ||
Expect(err).ShouldNot(HaveOccurred()) | ||
result, err = client.List(metav1.ListOptions{}) | ||
Expect(err).ShouldNot(HaveOccurred()) | ||
Expect(result.Items).To(HaveLen(0)) | ||
}) | ||
}) | ||
}) | ||
}) |
54 changes: 54 additions & 0 deletions
54
...controller/src/samplecontroller/pkg/apis/samplecontroller/v1alpha1/v1alpha1_suite_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
|
||
/* | ||
Copyright 2017 The Kubernetes 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 v1alpha1_test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
"github.com/kubernetes-sigs/kubebuilder/pkg/test" | ||
"k8s.io/client-go/rest" | ||
|
||
"samplecontroller/pkg/inject" | ||
"samplecontroller/pkg/client/clientset/versioned" | ||
) | ||
|
||
var testenv *test.TestEnvironment | ||
var config *rest.Config | ||
var cs *versioned.Clientset | ||
|
||
func TestV1alpha1(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecsWithDefaultAndCustomReporters(t, "v1 Suite", []Reporter{test.NewlineReporter{}}) | ||
} | ||
|
||
var _ = BeforeSuite(func() { | ||
testenv = &test.TestEnvironment{CRDs: inject.Injector.CRDs} | ||
|
||
var err error | ||
config, err = testenv.Start() | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
cs = versioned.NewForConfigOrDie(config) | ||
}) | ||
|
||
var _ = AfterSuite(func() { | ||
testenv.Stop() | ||
}) |
Oops, something went wrong.