Skip to content

Commit 28e76ec

Browse files
committed
DO NOT MERGE: Example of a controller that starts and stops further controllers
Signed-off-by: Nic Cope <[email protected]>
1 parent 4640860 commit 28e76ec

File tree

12 files changed

+748
-19
lines changed

12 files changed

+748
-19
lines changed

apis/apis.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/crossplane/crossplane/apis/cache"
2424
"github.com/crossplane/crossplane/apis/compute"
2525
"github.com/crossplane/crossplane/apis/database"
26+
"github.com/crossplane/crossplane/apis/experimental"
2627
"github.com/crossplane/crossplane/apis/kubernetes"
2728
"github.com/crossplane/crossplane/apis/oam"
2829
"github.com/crossplane/crossplane/apis/stacks"
@@ -36,6 +37,7 @@ func init() {
3637
cache.AddToScheme,
3738
compute.AddToScheme,
3839
database.AddToScheme,
40+
experimental.AddToScheme,
3941
kubernetes.AddToScheme,
4042
oam.AddToScheme,
4143
stacks.AddToScheme,

apis/experimental/cache.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
Copyright 2019 The Crossplane Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// Package experimental contains experimental API versions
18+
package experimental
19+
20+
import (
21+
"k8s.io/apimachinery/pkg/runtime"
22+
23+
"github.com/crossplane/crossplane/apis/experimental/v1alpha1"
24+
)
25+
26+
func init() {
27+
// Register the types with the Scheme so the components can map objects to GroupVersionKinds and back
28+
AddToSchemes = append(AddToSchemes, v1alpha1.SchemeBuilder.AddToScheme)
29+
}
30+
31+
// AddToSchemes may be used to add all resources defined in the project to a Scheme
32+
var AddToSchemes runtime.SchemeBuilder
33+
34+
// AddToScheme adds all Resources to the Scheme
35+
func AddToScheme(s *runtime.Scheme) error {
36+
return AddToSchemes.AddToScheme(s)
37+
}

apis/experimental/v1alpha1/doc.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
Copyright 2019 The Crossplane Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// Package v1alpha1 contains experiments.
18+
// +kubebuilder:object:generate=true
19+
// +groupName=experimental.crossplane.io
20+
// +versionName=v1alpha1
21+
package v1alpha1
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
Copyright 2019 The Crossplane Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha1
18+
19+
import (
20+
"reflect"
21+
22+
"k8s.io/apimachinery/pkg/runtime/schema"
23+
"sigs.k8s.io/controller-runtime/pkg/scheme"
24+
)
25+
26+
// Package type metadata.
27+
const (
28+
Group = "experimental.crossplane.io"
29+
Version = "v1alpha1"
30+
)
31+
32+
var (
33+
// SchemeGroupVersion is group version used to register these objects
34+
SchemeGroupVersion = schema.GroupVersion{Group: Group, Version: Version}
35+
36+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
37+
SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion}
38+
)
39+
40+
// Experiment type metadata.
41+
var (
42+
ExperimentKind = reflect.TypeOf(Experiment{}).Name()
43+
ExperimentGroupKind = schema.GroupKind{Group: Group, Kind: ExperimentKind}.String()
44+
ExperimentKindAPIVersion = ExperimentKind + "." + SchemeGroupVersion.String()
45+
ExperimentGroupVersionKind = SchemeGroupVersion.WithKind(ExperimentKind)
46+
)
47+
48+
func init() {
49+
SchemeBuilder.Register(&Experiment{}, &ExperimentList{})
50+
}

apis/experimental/v1alpha1/types.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
Copyright 2019 The Crossplane Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha1
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
)
22+
23+
// Watch for a kind of resource.
24+
type Watch struct {
25+
APIVersion string `json:"apiVersion"`
26+
Kind string `json:"kind"`
27+
}
28+
29+
// ExperimentSpec specifies the desired state of a Experiment.
30+
type ExperimentSpec struct {
31+
// Watch for a kind of resource.
32+
Watch Watch `json:"watch"`
33+
}
34+
35+
// +kubebuilder:object:root=true
36+
37+
// A Experiment starts a controller when an instance of a
38+
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp"
39+
// +kubebuilder:resource:scope=Cluster
40+
type Experiment struct {
41+
metav1.TypeMeta `json:",inline"`
42+
metav1.ObjectMeta `json:"metadata,omitempty"`
43+
44+
Spec ExperimentSpec `json:"spec,omitempty"`
45+
}
46+
47+
// +kubebuilder:object:root=true
48+
49+
// ExperimentList contains a list of Experiment.
50+
type ExperimentList struct {
51+
metav1.TypeMeta `json:",inline"`
52+
metav1.ListMeta `json:"metadata,omitempty"`
53+
Items []Experiment `json:"items"`
54+
}

apis/experimental/v1alpha1/zz_generated.deepcopy.go

Lines changed: 114 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
2+
---
3+
apiVersion: apiextensions.k8s.io/v1beta1
4+
kind: CustomResourceDefinition
5+
metadata:
6+
annotations:
7+
controller-gen.kubebuilder.io/version: v0.2.4
8+
creationTimestamp: null
9+
name: experiments.experimental.crossplane.io
10+
spec:
11+
additionalPrinterColumns:
12+
- JSONPath: .metadata.creationTimestamp
13+
name: AGE
14+
type: date
15+
group: experimental.crossplane.io
16+
names:
17+
kind: Experiment
18+
listKind: ExperimentList
19+
plural: experiments
20+
singular: experiment
21+
scope: Cluster
22+
subresources: {}
23+
validation:
24+
openAPIV3Schema:
25+
description: A Experiment starts a controller when an instance of a
26+
properties:
27+
apiVersion:
28+
description: 'APIVersion defines the versioned schema of this representation
29+
of an object. Servers should convert recognized schemas to the latest
30+
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
31+
type: string
32+
kind:
33+
description: 'Kind is a string value representing the REST resource this
34+
object represents. Servers may infer this from the endpoint the client
35+
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
36+
type: string
37+
metadata:
38+
type: object
39+
spec:
40+
description: ExperimentSpec specifies the desired state of a Experiment.
41+
properties:
42+
watch:
43+
description: Watch for a kind of resource.
44+
properties:
45+
apiVersion:
46+
type: string
47+
kind:
48+
type: string
49+
required:
50+
- apiVersion
51+
- kind
52+
type: object
53+
required:
54+
- watch
55+
type: object
56+
type: object
57+
version: v1alpha1
58+
versions:
59+
- name: v1alpha1
60+
served: true
61+
storage: true
62+
status:
63+
acceptedNames:
64+
kind: ""
65+
plural: ""
66+
conditions: []
67+
storedVersions: []

0 commit comments

Comments
 (0)