Skip to content

Commit 0ce7b68

Browse files
committed
v1alpha2 LeaseCandidate API
1 parent 210f129 commit 0ce7b68

36 files changed

+545
-2163
lines changed

cmd/kube-controller-manager/app/controllermanager.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ func Run(ctx context.Context, c *config.CompletedConfig) error {
298298
"kube-controller-manager",
299299
binaryVersion.FinalizeVersion(),
300300
emulationVersion.FinalizeVersion(),
301-
[]coordinationv1.CoordinatedLeaseStrategy{coordinationv1.OldestEmulationVersion},
301+
coordinationv1.OldestEmulationVersion,
302302
)
303303
if err != nil {
304304
return err

cmd/kube-scheduler/app/server.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ func Run(ctx context.Context, cc *schedulerserverconfig.CompletedConfig, sched *
227227
"kube-scheduler",
228228
binaryVersion.FinalizeVersion(),
229229
emulationVersion.FinalizeVersion(),
230-
[]coordinationv1.CoordinatedLeaseStrategy{coordinationv1.OldestEmulationVersion},
230+
coordinationv1.OldestEmulationVersion,
231231
)
232232
if err != nil {
233233
return err

hack/lib/init.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ batch/v1beta1 \
8989
certificates.k8s.io/v1 \
9090
certificates.k8s.io/v1beta1 \
9191
certificates.k8s.io/v1alpha1 \
92-
coordination.k8s.io/v1alpha1 \
92+
coordination.k8s.io/v1alpha2 \
9393
coordination.k8s.io/v1beta1 \
9494
coordination.k8s.io/v1 \
9595
discovery.k8s.io/v1 \

pkg/apis/coordination/install/install.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
"k8s.io/kubernetes/pkg/api/legacyscheme"
2525
"k8s.io/kubernetes/pkg/apis/coordination"
2626
v1 "k8s.io/kubernetes/pkg/apis/coordination/v1"
27-
"k8s.io/kubernetes/pkg/apis/coordination/v1alpha1"
27+
"k8s.io/kubernetes/pkg/apis/coordination/v1alpha2"
2828
"k8s.io/kubernetes/pkg/apis/coordination/v1beta1"
2929
)
3030

@@ -35,8 +35,8 @@ func init() {
3535
// Install registers the API group and adds types to a scheme
3636
func Install(scheme *runtime.Scheme) {
3737
utilruntime.Must(coordination.AddToScheme(scheme))
38-
utilruntime.Must(v1alpha1.AddToScheme(scheme))
38+
utilruntime.Must(v1alpha2.AddToScheme(scheme))
3939
utilruntime.Must(v1beta1.AddToScheme(scheme))
4040
utilruntime.Must(v1.AddToScheme(scheme))
41-
utilruntime.Must(scheme.SetVersionPriority(v1.SchemeGroupVersion, v1beta1.SchemeGroupVersion, v1alpha1.SchemeGroupVersion))
41+
utilruntime.Must(scheme.SetVersionPriority(v1.SchemeGroupVersion, v1beta1.SchemeGroupVersion, v1alpha2.SchemeGroupVersion))
4242
}

pkg/apis/coordination/types.go

+7-11
Original file line numberDiff line numberDiff line change
@@ -126,27 +126,23 @@ type LeaseCandidateSpec struct {
126126
// +optional
127127
RenewTime *metav1.MicroTime
128128
// BinaryVersion is the binary version. It must be in a semver format without leading `v`.
129-
// This field is required when strategy is "OldestEmulationVersion"
130-
// +optional
129+
// This field is required.
130+
// +required
131131
BinaryVersion string
132132
// EmulationVersion is the emulation version. It must be in a semver format without leading `v`.
133133
// EmulationVersion must be less than or equal to BinaryVersion.
134134
// This field is required when strategy is "OldestEmulationVersion"
135135
// +optional
136136
EmulationVersion string
137-
// PreferredStrategies indicates the list of strategies for picking the leader for coordinated leader election.
138-
// The list is ordered, and the first strategy supersedes all other strategies. The list is used by coordinated
139-
// leader election to make a decision about the final election strategy. This follows as
140-
// - If all clients have strategy X as the first element in this list, strategy X will be used.
141-
// - If a candidate has strategy [X] and another candidate has strategy [Y, X], Y supersedes X and strategy Y
142-
// will be used.
143-
// - If a candidate has strategy [X, Y] and another candidate has strategy [Y, X], this is a user error and leader
144-
// election will not operate the Lease until resolved.
137+
// Strategy is the strategy that coordinated leader election will use for picking the leader.
138+
// If multiple candidates for the same Lease return different strategies, the strategy provided
139+
// by the candidate with the latest BinaryVersion will be used. If there is still conflict,
140+
// this is a user error and coordinated leader election will not operate the Lease until resolved.
145141
// (Alpha) Using this field requires the CoordinatedLeaderElection feature gate to be enabled.
146142
// +featureGate=CoordinatedLeaderElection
147143
// +listType=atomic
148144
// +required
149-
PreferredStrategies []CoordinatedLeaseStrategy
145+
Strategy CoordinatedLeaseStrategy
150146
}
151147

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

pkg/apis/coordination/v1alpha1/zz_generated.conversion.go

-151
This file was deleted.

pkg/apis/coordination/v1alpha1/zz_generated.defaults.go

-33
This file was deleted.

pkg/apis/coordination/v1alpha1/doc.go pkg/apis/coordination/v1alpha2/doc.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ limitations under the License.
1515
*/
1616

1717
// +k8s:conversion-gen=k8s.io/kubernetes/pkg/apis/coordination
18-
// +k8s:conversion-gen-external-types=k8s.io/api/coordination/v1alpha1
18+
// +k8s:conversion-gen-external-types=k8s.io/api/coordination/v1alpha2
1919
// +k8s:defaulter-gen=TypeMeta
20-
// +k8s:defaulter-gen-input=k8s.io/api/coordination/v1alpha1
20+
// +k8s:defaulter-gen-input=k8s.io/api/coordination/v1alpha2
2121

2222
// +groupName=coordination.k8s.io
2323

24-
package v1alpha1 // import "k8s.io/kubernetes/pkg/apis/coordination/v1alpha1"
24+
package v1alpha2 // import "k8s.io/kubernetes/pkg/apis/coordination/v1alpha2"

pkg/apis/coordination/v1alpha1/register.go pkg/apis/coordination/v1alpha2/register.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,26 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package v1alpha1
17+
package v1alpha2
1818

1919
import (
20-
coordinationv1alpha1 "k8s.io/api/coordination/v1alpha1"
20+
coordinationv1alpha2 "k8s.io/api/coordination/v1alpha2"
2121
"k8s.io/apimachinery/pkg/runtime/schema"
2222
)
2323

2424
// GroupName is the group name use in this package
2525
const GroupName = "coordination.k8s.io"
2626

2727
// SchemeGroupVersion is group version used to register these objects
28-
var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1alpha1"}
28+
var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1alpha2"}
2929

3030
// Resource takes an unqualified resource and returns a Group qualified GroupResource
3131
func Resource(resource string) schema.GroupResource {
3232
return SchemeGroupVersion.WithResource(resource).GroupResource()
3333
}
3434

3535
var (
36-
localSchemeBuilder = &coordinationv1alpha1.SchemeBuilder
36+
localSchemeBuilder = &coordinationv1alpha2.SchemeBuilder
3737
// AddToScheme is a common registration function for mapping packaged scoped group & version keys to a scheme
3838
AddToScheme = localSchemeBuilder.AddToScheme
3939
)

pkg/apis/coordination/validation/validation.go

+13-22
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ func ValidateLeaseCandidateSpec(spec *coordination.LeaseCandidateSpec, fldPath *
111111
}
112112
}
113113
bv := semver.Version{}
114-
if spec.BinaryVersion != "" {
114+
if spec.BinaryVersion == "" {
115+
allErrs = append(allErrs, field.Required(fldPath.Child("binaryVersion"), ""))
116+
} else {
115117
var err error
116118
bv, err = semver.Parse(spec.BinaryVersion)
117119
if err != nil {
@@ -124,29 +126,18 @@ func ValidateLeaseCandidateSpec(spec *coordination.LeaseCandidateSpec, fldPath *
124126
allErrs = append(allErrs, field.Invalid(fld, spec.BinaryVersion, "must be greater than or equal to `emulationVersion`"))
125127
}
126128

127-
if len(spec.PreferredStrategies) > 0 {
128-
for i, strategy := range spec.PreferredStrategies {
129-
fld := fldPath.Child("preferredStrategies").Index(i)
130-
131-
strategySeen := make(map[coordination.CoordinatedLeaseStrategy]bool)
132-
if _, ok := strategySeen[strategy]; ok {
133-
allErrs = append(allErrs, field.Duplicate(fld, strategy))
134-
} else {
135-
strategySeen[strategy] = true
136-
}
137-
138-
if strategy == coordination.OldestEmulationVersion {
139-
zeroVersion := semver.Version{}
140-
if bv.EQ(zeroVersion) {
141-
allErrs = append(allErrs, field.Required(fldPath.Child("binaryVersion"), "must be specified when `strategy` is 'OldestEmulationVersion'"))
142-
}
143-
if ev.EQ(zeroVersion) {
144-
allErrs = append(allErrs, field.Required(fldPath.Child("emulationVersion"), "must be specified when `strategy` is 'OldestEmulationVersion'"))
145-
}
129+
if spec.Strategy == "" {
130+
allErrs = append(allErrs, field.Required(fldPath.Child("strategy"), ""))
131+
} else {
132+
fld := fldPath.Child("strategy")
133+
if spec.Strategy == coordination.OldestEmulationVersion {
134+
zeroVersion := semver.Version{}
135+
if ev.EQ(zeroVersion) {
136+
allErrs = append(allErrs, field.Required(fldPath.Child("emulationVersion"), "must be specified when `strategy` is 'OldestEmulationVersion'"))
146137
}
147-
148-
allErrs = append(allErrs, ValidateCoordinatedLeaseStrategy(strategy, fld)...)
149138
}
139+
140+
allErrs = append(allErrs, ValidateCoordinatedLeaseStrategy(spec.Strategy, fld)...)
150141
}
151142
// spec.PingTime is a MicroTime and doesn't need further validation
152143
// spec.RenewTime is a MicroTime and doesn't need further validation

0 commit comments

Comments
 (0)