Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[kwokctl] Support version skew #639

Merged
merged 1 commit into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pkg/apis/config/v1alpha1/kwokctl_configuration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ type KwokctlConfiguration struct {
Components []Component `json:"components,omitempty" patchStrategy:"merge" patchMergeKey:"name"`
// ComponentsPatches holds information about the components patches.
ComponentsPatches []ComponentPatches `json:"componentsPatches,omitempty" patchStrategy:"merge" patchMergeKey:"name"`
// Status holds information about the status.
Status KwokctlConfigurationStatus `json:"status,omitempty"`
}

// KwokctlConfigurationStatus holds information about the status.
type KwokctlConfigurationStatus struct {
// Version is the version of the kwokctl.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is Version this meaning?

Version is the version of kwokctl that created this cluster.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep

Version string `json:"version,omitempty"`
}

// ExtraArgs holds information about the extra args.
Expand Down
17 changes: 17 additions & 0 deletions pkg/apis/config/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions pkg/apis/internalversion/kwokctl_configuration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ type KwokctlConfiguration struct {
Components []Component
// ComponentsPatches holds information about the components patches.
ComponentsPatches []ComponentPatches
// Status holds information about the status.
Status KwokctlConfigurationStatus
}

// KwokctlConfigurationStatus holds information about the status.
type KwokctlConfigurationStatus struct {
// Version is the version of the kwokctl.
Version string
}

// ExtraArgs holds information about the extra args.
Expand Down
36 changes: 36 additions & 0 deletions pkg/apis/internalversion/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions pkg/apis/internalversion/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 45 additions & 5 deletions pkg/kwokctl/runtime/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"sigs.k8s.io/kwok/pkg/utils/format"
"sigs.k8s.io/kwok/pkg/utils/path"
"sigs.k8s.io/kwok/pkg/utils/slices"
"sigs.k8s.io/kwok/pkg/utils/version"
"sigs.k8s.io/kwok/pkg/utils/wait"
"sigs.k8s.io/kwok/stages"
)
Expand Down Expand Up @@ -85,6 +86,39 @@ func (c *Cluster) Config(ctx context.Context) (*internalversion.KwokctlConfigura
return conf, err
}
c.conf = conf
logger := log.FromContext(ctx)
if conf.Status.Version == "" {
logger.Warn("The cluster was created by an older version of kwokctl, "+
"please recreate the cluster",
"createdByVersion", "<0.3.0",
"kwokctlVersion", consts.Version,
)
conf.Status.Version = "0.0.0"
} else if conf.Status.Version != consts.Version {
currentVer, err := version.ParseVersion(conf.Status.Version)
if err != nil {
return nil, err
}
ver, err := version.ParseVersion(consts.Version)
if err != nil {
return nil, err
}
switch {
case currentVer.LT(ver):
logger.Warn("The cluster was created by a older version of kwokctl, "+
"please recreate the cluster",
"createdByVersion", conf.Status.Version,
"kwokctlVersion", consts.Version,
)
case currentVer.GT(ver):
logger.Warn("The cluster was created by a newer version of kwokctl, "+
"please upgrade kwokctl or recreate the cluster",
"createdByVersion", conf.Status.Version,
"kwokctlVersion", consts.Version,
)
}
}

return conf, nil
}

Expand Down Expand Up @@ -124,17 +158,23 @@ func (c *Cluster) Save(ctx context.Context) error {
return nil
}

conf := c.conf.DeepCopy()
objs := []config.InternalObject{
c.conf,
conf,
}

if conf.Status.Version == "" {
c.conf = c.conf.DeepCopy()
c.conf.Status.Version = consts.Version
}

others := config.FilterWithoutTypeFromContext[*internalversion.KwokctlConfiguration](ctx)
objs = append(objs, others...)

if c.conf.Options.NodeLeaseDurationSeconds == 0 {
if updateFrequency := c.conf.Options.NodeStatusUpdateFrequencyMilliseconds; updateFrequency > 0 &&
c.conf.Options.Runtime != consts.RuntimeTypeKind &&
c.conf.Options.Runtime != consts.RuntimeTypeKindPodman &&
if conf.Options.NodeLeaseDurationSeconds == 0 {
if updateFrequency := conf.Options.NodeStatusUpdateFrequencyMilliseconds; updateFrequency > 0 &&
conf.Options.Runtime != consts.RuntimeTypeKind &&
conf.Options.Runtime != consts.RuntimeTypeKindPodman &&
len(config.FilterWithTypeFromContext[*internalversion.Stage](ctx)) == 0 {
nodeStages, err := controllers.NewStagesFromYaml([]byte(stages.DefaultNodeStages))
if err != nil {
Expand Down
45 changes: 45 additions & 0 deletions site/content/en/docs/generated/apis.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,19 @@ KwokctlConfigurationOptions
<p>ComponentsPatches holds information about the components patches.</p>
</td>
</tr>
<tr>
<td>
<code>status</code>
<em>
<a href="#config.kwok.x-k8s.io/v1alpha1.KwokctlConfigurationStatus">
KwokctlConfigurationStatus
</a>
</em>
</td>
<td>
<p>Status holds information about the status.</p>
</td>
</tr>
</tbody>
</table>
<h2 id="kwok.x-k8s.io/v1alpha1">
Expand Down Expand Up @@ -2548,6 +2561,38 @@ bool
</tr>
</tbody>
</table>
<h3 id="config.kwok.x-k8s.io/v1alpha1.KwokctlConfigurationStatus">
KwokctlConfigurationStatus
<a href="#config.kwok.x-k8s.io%2fv1alpha1.KwokctlConfigurationStatus"> #</a>
</h3>
<p>
<em>Appears on: </em>
<a href="#config.kwok.x-k8s.io/v1alpha1.KwokctlConfiguration">KwokctlConfiguration</a>
</p>
<p>
<p>KwokctlConfigurationStatus holds information about the status.</p>
</p>
<table>
<thead>
<tr>
<th>Field</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code>version</code>
<em>
string
</em>
</td>
<td>
<p>Version is the version of the kwokctl.</p>
</td>
</tr>
</tbody>
</table>
<h3 id="config.kwok.x-k8s.io/v1alpha1.Port">
Port
<a href="#config.kwok.x-k8s.io%2fv1alpha1.Port"> #</a>
Expand Down