Skip to content

Commit

Permalink
Make the min version CNO supports frr-k8s parametric
Browse files Browse the repository at this point in the history
Openshift only behavior: at some point the operator will have to signal
Openshift's Cluster Network Operator to install frr-k8s. This is to make
the minimum version supporting it parametric.

Signed-off-by: Federico Paolinelli <[email protected]>
  • Loading branch information
fedepaol authored and oribon committed Feb 10, 2025
1 parent 624f7a2 commit 419ebaf
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion controllers/metallb_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (r *MetalLBReconciler) syncMetalLBResources(ctx context.Context, config *me

bgpType := params.BGPType(config, r.EnvConfig)
if r.EnvConfig.MustDeployFRRK8sFromCNO && r.EnvConfig.IsOpenshift && (bgpType == metallbv1beta1.FRRK8sExternalMode) {
supportsFRRK8s, err := openshift.SupportsFRRK8s(ctx, r.Client)
supportsFRRK8s, err := openshift.SupportsFRRK8s(ctx, r.Client, r.EnvConfig)
if err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ require (

require (
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 // indirect
github.com/Masterminds/semver v1.5.0 // indirect
github.com/Microsoft/hcsshim v0.11.4 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,8 @@ github.com/MakeNowJust/heredoc v1.0.0 h1:cXCdzVdstXyiTqTvfqk9SDHpKNjxuom+DOlyEeQ
github.com/MakeNowJust/heredoc v1.0.0/go.mod h1:mG5amYoWBHf8vpLOuehzbGGw0EHxpZZ6lCpQ4fNJ8LE=
github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI=
github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww=
github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
github.com/Masterminds/semver/v3 v3.2.0/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0=
github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
Expand Down
9 changes: 5 additions & 4 deletions pkg/openshift/openshift.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,35 @@ import (
"slices"

"github.com/Masterminds/semver/v3"
"github.com/metallb/metallb-operator/pkg/params"
openshiftconfigv1 "github.com/openshift/api/config/v1"
openshiftapiv1 "github.com/openshift/api/operator/v1"
"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
)

func SupportsFRRK8s(ctx context.Context, cli client.Client) (bool, error) {
func SupportsFRRK8s(ctx context.Context, cli client.Client, envConfig params.EnvConfig) (bool, error) {
cno := &openshiftconfigv1.ClusterOperator{}
err := cli.Get(ctx, types.NamespacedName{Name: "network"}, cno)
if err != nil {
return false, errors.Wrapf(err, "get openshift network operator failed")
}
supports, err := cnoSupportsFRRK8s(cno)
supports, err := cnoSupportsFRRK8s(cno, envConfig)
if err != nil {
return false, err
}
return supports, nil
}

func cnoSupportsFRRK8s(cno *openshiftconfigv1.ClusterOperator) (bool, error) {
func cnoSupportsFRRK8s(cno *openshiftconfigv1.ClusterOperator, envConfig params.EnvConfig) (bool, error) {
for _, v := range cno.Status.Versions {
if v.Name == "operator" {
v, err := semver.NewVersion(v.Version)
if err != nil {
return false, errors.Wrapf(err, "failed to parse semver for network operator")
}
validVersion, _ := semver.NewVersion("4.17.0-0")
validVersion, _ := semver.NewVersion(envConfig.CNOMinFRRK8sVersion)
valid := !v.LessThan(validVersion)
return valid, nil
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/openshift/openshift_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package openshift
import (
"testing"

"github.com/metallb/metallb-operator/pkg/params"
openshiftconfigv1 "github.com/openshift/api/config/v1"
)

Expand Down Expand Up @@ -103,7 +104,8 @@ func TestCnoSupportsFRRK8s(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
supports, err := cnoSupportsFRRK8s(test.cno)
envConfig := params.EnvConfig{CNOMinFRRK8sVersion: "4.17.0-0"}
supports, err := cnoSupportsFRRK8s(test.cno, envConfig)
if test.shouldErr && err == nil {
t.Fatalf("expected error, got nil")
}
Expand Down
9 changes: 9 additions & 0 deletions pkg/params/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strconv"
"strings"

"github.com/Masterminds/semver"
"github.com/metallb/metallb-operator/api/v1beta1"
)

Expand Down Expand Up @@ -36,6 +37,7 @@ type EnvConfig struct {
FRRImage ImageInfo
FRRK8sImage ImageInfo
KubeRBacImage ImageInfo
CNOMinFRRK8sVersion string
MLBindPort int
FRRMetricsPort int
SecureFRRMetricsPort int
Expand Down Expand Up @@ -133,6 +135,7 @@ func FromEnvironment(isOpenshift bool) (EnvConfig, error) {

// Ignoring the error, if not set we'll consume the image from the chart
res.FRRK8sImage, _ = imageFromEnv("FRRK8S_IMAGE")
res.CNOMinFRRK8sVersion = os.Getenv("CNO_MIN_FRRK8S_VERSION")

err = validate(res)
if err != nil {
Expand All @@ -152,6 +155,12 @@ func validate(config EnvConfig) error {
if config.SecureFRRMetricsPort != 0 && !config.DeployServiceMonitors {
return fmt.Errorf("secureFRRMetricsPort is available only if service monitors are enabled")
}
if config.CNOMinFRRK8sVersion != "" {
_, err := semver.NewVersion(config.CNOMinFRRK8sVersion)
if err != nil {
return fmt.Errorf("invalid cno min frrk8s supported version: %w", err)
}
}
return nil
}

Expand Down

0 comments on commit 419ebaf

Please sign in to comment.