Skip to content

Commit d025467

Browse files
authored
Merge pull request #17 from weaveworks/multi-bootstrap-bump-api
Bump the apiVersion to avoid issues with the multi-bootstrap changes. When we changed to support multiple bootstrappers, this can cause issues for existing clusters.
2 parents d36def5 + 448cb59 commit d025467

12 files changed

+7607
-54
lines changed
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/*
2+
Copyright 2021.
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 v1alpha2
18+
19+
import (
20+
"time"
21+
22+
corev1 "k8s.io/api/core/v1"
23+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24+
)
25+
26+
const defaultWaitDuration = time.Second * 60
27+
28+
const (
29+
BootstrappedAnnotation = "capi.weave.works/bootstrapped"
30+
BootstrapConfigsAnnotation = "capi.weave.works/bootstrap-configs"
31+
)
32+
33+
// JobTemplate describes a job to create
34+
type JobTemplate struct {
35+
// DNS1032 compatible name used as a prefix when generating the Job from the
36+
// Spec.
37+
GenerateName string `json:"generateName"`
38+
// Specifies the number of retries before marking this job failed.
39+
// Defaults to 6
40+
//+kubebuilder:validation:Optional
41+
//+kubebuilder:default:=6
42+
BackoffLimit *int32 `json:"backoffLimit,optional"`
43+
44+
// ttlSecondsAfterFinished limits the lifetime of a Job that has finished
45+
// execution (either Complete or Failed). If this field is set,
46+
// ttlSecondsAfterFinished after the Job finishes, it is eligible to be
47+
// automatically deleted. When the Job is being deleted, its lifecycle
48+
// guarantees (e.g. finalizers) will be honored. If this field is unset,
49+
// the Job won't be automatically deleted. If this field is set to zero,
50+
// the Job becomes eligible to be deleted immediately after it finishes.
51+
//+optional
52+
TTLSecondsAfterFinished *int32 `json:"ttlSecondsAfterFinished,omitempty"`
53+
54+
// A batch/v1 Job is created with the Spec as the PodSpec.
55+
Spec corev1.PodSpec `json:"spec"`
56+
}
57+
58+
// ClusterBootstrapConfigSpec defines the desired state of ClusterBootstrapConfig
59+
type ClusterBootstrapConfigSpec struct {
60+
ClusterSelector metav1.LabelSelector `json:"clusterSelector"`
61+
Template JobTemplate `json:"jobTemplate"`
62+
63+
// Trigger the bootstrapping when the linked cluster has a True
64+
// "ClusterProvisioned" condition.
65+
//
66+
// A new job will not be triggered when the cluster is finally "Ready"
67+
// because it will already have the annotation that indicates the cluster
68+
// has been bootstrapped.
69+
//
70+
// Defaults to false.
71+
//+kubebuilder:default:false
72+
//+optional
73+
RequireClusterProvisioned bool `json:"requireClusterProvisioned"`
74+
75+
// Wait for the remote cluster to be "ready" before creating the jobs.
76+
// Defaults to false.
77+
//+kubebuilder:default:false
78+
//+optional
79+
RequireClusterReady bool `json:"requireClusterReady"`
80+
// When checking for readiness, this is the time to wait before
81+
// checking again.
82+
//+kubebuilder:default:60s
83+
//+optional
84+
ClusterReadinessBackoff *metav1.Duration `json:"clusterReadinessBackoff,omitempty"`
85+
}
86+
87+
// ClusterBootstrapConfigStatus defines the observed state of ClusterBootstrapConfig
88+
type ClusterBootstrapConfigStatus struct {
89+
}
90+
91+
//+kubebuilder:object:root=true
92+
//+kubebuilder:subresource:status
93+
//+kubebuilder:storageversion
94+
95+
// ClusterBootstrapConfig is the Schema for the clusterbootstrapconfigs API
96+
type ClusterBootstrapConfig struct {
97+
metav1.TypeMeta `json:",inline"`
98+
metav1.ObjectMeta `json:"metadata,omitempty"`
99+
100+
Spec ClusterBootstrapConfigSpec `json:"spec,omitempty"`
101+
Status ClusterBootstrapConfigStatus `json:"status,omitempty"`
102+
}
103+
104+
// ClusterReadinessRequeue returns the configured ClusterReadinessBackoff or a default
105+
// value if not configured.
106+
func (c ClusterBootstrapConfig) ClusterReadinessRequeue() time.Duration {
107+
if v := c.Spec.ClusterReadinessBackoff; v != nil {
108+
return v.Duration
109+
}
110+
return defaultWaitDuration
111+
}
112+
113+
//+kubebuilder:object:root=true
114+
115+
// ClusterBootstrapConfigList contains a list of ClusterBootstrapConfig
116+
type ClusterBootstrapConfigList struct {
117+
metav1.TypeMeta `json:",inline"`
118+
metav1.ListMeta `json:"metadata,omitempty"`
119+
Items []ClusterBootstrapConfig `json:"items"`
120+
}
121+
122+
func init() {
123+
SchemeBuilder.Register(&ClusterBootstrapConfig{}, &ClusterBootstrapConfigList{})
124+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
Copyright 2022.
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 v1alpha2
18+
19+
import (
20+
"testing"
21+
"time"
22+
23+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24+
)
25+
26+
func TestControl(t *testing.T) {
27+
cfg := ClusterBootstrapConfig{}
28+
29+
if v := cfg.ClusterReadinessRequeue(); v != defaultWaitDuration {
30+
t.Fatalf("ClusterReadinessRequeue() got %v, want %v", v, defaultWaitDuration)
31+
}
32+
33+
want := time.Second * 20
34+
cfg.Spec.ClusterReadinessBackoff = &metav1.Duration{Duration: want}
35+
if v := cfg.ClusterReadinessRequeue(); v != want {
36+
t.Fatalf("ClusterReadinessRequeue() got %v, want %v", v, want)
37+
}
38+
}

api/v1alpha2/groupversion_info.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Copyright 2021.
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 v1alpha2 contains API Schema definitions for the capi v1alpha2 API group
18+
// +kubebuilder:object:generate=true
19+
// +groupName=capi.weave.works
20+
package v1alpha2
21+
22+
import (
23+
"k8s.io/apimachinery/pkg/runtime/schema"
24+
"sigs.k8s.io/controller-runtime/pkg/scheme"
25+
)
26+
27+
var (
28+
// GroupVersion is group version used to register these objects
29+
GroupVersion = schema.GroupVersion{Group: "capi.weave.works", Version: "v1alpha2"}
30+
31+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
32+
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
33+
34+
// AddToScheme adds the types in this group-version to the given scheme.
35+
AddToScheme = SchemeBuilder.AddToScheme
36+
)

api/v1alpha2/zz_generated.deepcopy.go

Lines changed: 149 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)