Skip to content

Commit

Permalink
v1alpha2 LeaseCandidate API
Browse files Browse the repository at this point in the history
  • Loading branch information
Jefftree committed Nov 8, 2024
1 parent 210f129 commit 0ce7b68
Show file tree
Hide file tree
Showing 36 changed files with 545 additions and 2,163 deletions.
2 changes: 1 addition & 1 deletion cmd/kube-controller-manager/app/controllermanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ func Run(ctx context.Context, c *config.CompletedConfig) error {
"kube-controller-manager",
binaryVersion.FinalizeVersion(),
emulationVersion.FinalizeVersion(),
[]coordinationv1.CoordinatedLeaseStrategy{coordinationv1.OldestEmulationVersion},
coordinationv1.OldestEmulationVersion,
)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/kube-scheduler/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func Run(ctx context.Context, cc *schedulerserverconfig.CompletedConfig, sched *
"kube-scheduler",
binaryVersion.FinalizeVersion(),
emulationVersion.FinalizeVersion(),
[]coordinationv1.CoordinatedLeaseStrategy{coordinationv1.OldestEmulationVersion},
coordinationv1.OldestEmulationVersion,
)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion hack/lib/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ batch/v1beta1 \
certificates.k8s.io/v1 \
certificates.k8s.io/v1beta1 \
certificates.k8s.io/v1alpha1 \
coordination.k8s.io/v1alpha1 \
coordination.k8s.io/v1alpha2 \
coordination.k8s.io/v1beta1 \
coordination.k8s.io/v1 \
discovery.k8s.io/v1 \
Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/coordination/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/apis/coordination"
v1 "k8s.io/kubernetes/pkg/apis/coordination/v1"
"k8s.io/kubernetes/pkg/apis/coordination/v1alpha1"
"k8s.io/kubernetes/pkg/apis/coordination/v1alpha2"
"k8s.io/kubernetes/pkg/apis/coordination/v1beta1"
)

Expand All @@ -35,8 +35,8 @@ func init() {
// Install registers the API group and adds types to a scheme
func Install(scheme *runtime.Scheme) {
utilruntime.Must(coordination.AddToScheme(scheme))
utilruntime.Must(v1alpha1.AddToScheme(scheme))
utilruntime.Must(v1alpha2.AddToScheme(scheme))
utilruntime.Must(v1beta1.AddToScheme(scheme))
utilruntime.Must(v1.AddToScheme(scheme))
utilruntime.Must(scheme.SetVersionPriority(v1.SchemeGroupVersion, v1beta1.SchemeGroupVersion, v1alpha1.SchemeGroupVersion))
utilruntime.Must(scheme.SetVersionPriority(v1.SchemeGroupVersion, v1beta1.SchemeGroupVersion, v1alpha2.SchemeGroupVersion))
}
18 changes: 7 additions & 11 deletions pkg/apis/coordination/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,27 +126,23 @@ type LeaseCandidateSpec struct {
// +optional
RenewTime *metav1.MicroTime
// BinaryVersion is the binary version. It must be in a semver format without leading `v`.
// This field is required when strategy is "OldestEmulationVersion"
// +optional
// This field is required.
// +required
BinaryVersion string
// EmulationVersion is the emulation version. It must be in a semver format without leading `v`.
// EmulationVersion must be less than or equal to BinaryVersion.
// This field is required when strategy is "OldestEmulationVersion"
// +optional
EmulationVersion string
// PreferredStrategies indicates the list of strategies for picking the leader for coordinated leader election.
// The list is ordered, and the first strategy supersedes all other strategies. The list is used by coordinated
// leader election to make a decision about the final election strategy. This follows as
// - If all clients have strategy X as the first element in this list, strategy X will be used.
// - If a candidate has strategy [X] and another candidate has strategy [Y, X], Y supersedes X and strategy Y
// will be used.
// - If a candidate has strategy [X, Y] and another candidate has strategy [Y, X], this is a user error and leader
// election will not operate the Lease until resolved.
// Strategy is the strategy that coordinated leader election will use for picking the leader.
// If multiple candidates for the same Lease return different strategies, the strategy provided
// by the candidate with the latest BinaryVersion will be used. If there is still conflict,
// this is a user error and coordinated leader election will not operate the Lease until resolved.
// (Alpha) Using this field requires the CoordinatedLeaderElection feature gate to be enabled.
// +featureGate=CoordinatedLeaderElection
// +listType=atomic
// +required
PreferredStrategies []CoordinatedLeaseStrategy
Strategy CoordinatedLeaseStrategy
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down
151 changes: 0 additions & 151 deletions pkg/apis/coordination/v1alpha1/zz_generated.conversion.go

This file was deleted.

33 changes: 0 additions & 33 deletions pkg/apis/coordination/v1alpha1/zz_generated.defaults.go

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ limitations under the License.
*/

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

// +groupName=coordination.k8s.io

package v1alpha1 // import "k8s.io/kubernetes/pkg/apis/coordination/v1alpha1"
package v1alpha2 // import "k8s.io/kubernetes/pkg/apis/coordination/v1alpha2"
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,26 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1
package v1alpha2

import (
coordinationv1alpha1 "k8s.io/api/coordination/v1alpha1"
coordinationv1alpha2 "k8s.io/api/coordination/v1alpha2"
"k8s.io/apimachinery/pkg/runtime/schema"
)

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

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

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

var (
localSchemeBuilder = &coordinationv1alpha1.SchemeBuilder
localSchemeBuilder = &coordinationv1alpha2.SchemeBuilder
// AddToScheme is a common registration function for mapping packaged scoped group & version keys to a scheme
AddToScheme = localSchemeBuilder.AddToScheme
)
Expand Down
35 changes: 13 additions & 22 deletions pkg/apis/coordination/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ func ValidateLeaseCandidateSpec(spec *coordination.LeaseCandidateSpec, fldPath *
}
}
bv := semver.Version{}
if spec.BinaryVersion != "" {
if spec.BinaryVersion == "" {
allErrs = append(allErrs, field.Required(fldPath.Child("binaryVersion"), ""))
} else {
var err error
bv, err = semver.Parse(spec.BinaryVersion)
if err != nil {
Expand All @@ -124,29 +126,18 @@ func ValidateLeaseCandidateSpec(spec *coordination.LeaseCandidateSpec, fldPath *
allErrs = append(allErrs, field.Invalid(fld, spec.BinaryVersion, "must be greater than or equal to `emulationVersion`"))
}

if len(spec.PreferredStrategies) > 0 {
for i, strategy := range spec.PreferredStrategies {
fld := fldPath.Child("preferredStrategies").Index(i)

strategySeen := make(map[coordination.CoordinatedLeaseStrategy]bool)
if _, ok := strategySeen[strategy]; ok {
allErrs = append(allErrs, field.Duplicate(fld, strategy))
} else {
strategySeen[strategy] = true
}

if strategy == coordination.OldestEmulationVersion {
zeroVersion := semver.Version{}
if bv.EQ(zeroVersion) {
allErrs = append(allErrs, field.Required(fldPath.Child("binaryVersion"), "must be specified when `strategy` is 'OldestEmulationVersion'"))
}
if ev.EQ(zeroVersion) {
allErrs = append(allErrs, field.Required(fldPath.Child("emulationVersion"), "must be specified when `strategy` is 'OldestEmulationVersion'"))
}
if spec.Strategy == "" {
allErrs = append(allErrs, field.Required(fldPath.Child("strategy"), ""))
} else {
fld := fldPath.Child("strategy")
if spec.Strategy == coordination.OldestEmulationVersion {
zeroVersion := semver.Version{}
if ev.EQ(zeroVersion) {
allErrs = append(allErrs, field.Required(fldPath.Child("emulationVersion"), "must be specified when `strategy` is 'OldestEmulationVersion'"))
}

allErrs = append(allErrs, ValidateCoordinatedLeaseStrategy(strategy, fld)...)
}

allErrs = append(allErrs, ValidateCoordinatedLeaseStrategy(spec.Strategy, fld)...)
}
// spec.PingTime is a MicroTime and doesn't need further validation
// spec.RenewTime is a MicroTime and doesn't need further validation
Expand Down
Loading

0 comments on commit 0ce7b68

Please sign in to comment.