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

Install iptables package based on the k0s version #547

Conversation

twz123
Copy link
Member

@twz123 twz123 commented Aug 30, 2023

Only install iptables if the k0s version requires it. Mark the corresponding host method as deprecated, as that code path can probably be completely removed in upcoming versions.

Fixes #363.

@twz123 twz123 added the chore Housekeeping / typo / code quality improvements label Aug 30, 2023
@twz123 twz123 force-pushed the iptables-installation-based-on-k0s-version branch from d27a913 to ace0933 Compare August 30, 2023 11:07
@twz123 twz123 marked this pull request as ready for review August 30, 2023 11:38
@kke
Copy link
Contributor

kke commented Aug 30, 2023

I've been trying to think of some clean way to use different strategies based on different k0s versions but haven't come up with a good one yet.

Something like:

strategy := versionstrategy.NewStrategy(
  versionstrategy.LessThan("v1.25.0"), func() {
    foofoo
  },
  func()  {
    barbar
  },
)
strategy.Run()

Or maybe just some helper like:

if p.Config.Spec.K0s.VersionLessThan("v1.25.0") {
   foofoo
}

Or maybe better for readability:

const k0sVersionWithFooFeature = version.MustCompile("v1.25.0")

...
...

if k0sVersionWithFooFeature.GreaterOrEqual(p.Config.Spec.K0s.Version) {
  legacyfoofoo
}

or perhaps:

const fooFeatureConstraint = versionconstraint.MustCompile(">= v1.25.0")

...
...

if fooFeatureConstraint.SatisfiedBy(p.Config.Spec.K0s.Version) {
  foofoo
}

@till
Copy link

till commented Aug 30, 2023

Maybe treat it as a general feature gate/flag thing? You could use it to enable/disable features too.

I think a => v1.2.3 style constraint is great. Most flexible. No need for less than or anything in code? In code you could use registry.IsEnabled("foo") and the basic scaffolding is:

type FeatureRegistry struct {
  // container for all flags
  Version string // p.Config.Spec.K0s.Version
}
func (f *FeatureRegistry) IsEnabled(feature string) bool {
  // fetch feature by its name from the registry
  // version constrain code here
  return true
}
func (f *FeatureRegistry) Add(feature FeatureGate) error {
  // for initial/global setup
  return nil
}
type FeatureGate struct {
  Name string
  Constraint versiontypestringsomething
}

Comment on lines +593 to +442
// Deprecated: iptables is only required for k0s versions that are unsupported
// for a long time already (< v1.22.1+k0s.0).
Copy link
Contributor

Choose a reason for hiding this comment

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

I think k0sctl still works for something like k0s v0.10.0 before the scheme switch.

The upgrade smoke currently starts from v1.21.6+k0s.0.

Should we start removing other stuff that was added to make k0sctl work with versions that are now unsupported? cc: @jnummelin

phase/prepare_hosts.go Outdated Show resolved Hide resolved
@kke kke force-pushed the iptables-installation-based-on-k0s-version branch from ace0933 to 1c9633d Compare September 6, 2023 12:36
@kke kke changed the base branch from main to version-v0.4.0 September 6, 2023 12:36
kke and others added 3 commits September 7, 2023 16:27
Only install iptables if the k0s version requires it. Mark the
corresponding host method as deprecated, as that code path can probably
be completely removed in upcoming versions.

Signed-off-by: Tom Wieczorek <[email protected]>
Signed-off-by: Kimmo Lehto <[email protected]>
Signed-off-by: Kimmo Lehto <[email protected]>
@kke kke force-pushed the iptables-installation-based-on-k0s-version branch from 1c9633d to a0509d1 Compare September 7, 2023 13:28
@kke kke deleted the branch k0sproject:version-v0.4.0 September 8, 2023 07:28
@kke kke closed this Sep 8, 2023
@twz123 twz123 deleted the iptables-installation-based-on-k0s-version branch September 8, 2023 08:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Housekeeping / typo / code quality improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Don't install iptables when it's not required
3 participants