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

connectivity: Detect version from cilium pods #987

Merged
merged 1 commit into from
Jul 22, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 24 additions & 0 deletions connectivity/check/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strings"
"time"

"github.com/blang/semver/v4"
"github.com/cilium/cilium/api/v1/observer"
ciliumv2 "github.com/cilium/cilium/pkg/k8s/apis/cilium.io/v2"
"google.golang.org/grpc"
Expand Down Expand Up @@ -484,6 +485,29 @@ func (ct *ConnectivityTest) initClients(ctx context.Context) error {
return nil
}

// DetectMinimumCiliumVersion returns the smallest Cilium version running in
// the cluster(s)
func (ct *ConnectivityTest) DetectMinimumCiliumVersion(ctx context.Context) (*semver.Version, error) {
var minVersion *semver.Version
for name, ciliumPod := range ct.ciliumPods {
stdout, err := ciliumPod.K8sClient.ExecInPodWithTTY(ctx, ciliumPod.Pod.Namespace, ciliumPod.Pod.Name,
defaults.AgentContainerName, []string{"cilium", "version", "-o", "jsonpath={$.Daemon.Version}"})
if err != nil {
return nil, fmt.Errorf("unable to fetch cilium version on pod %q: %w", name, err)
}
v, _, _ := strings.Cut(stdout.String(), "-") // strips proprietary -releaseX suffix
podVersion, err := semver.Parse(v)
if err != nil {
return nil, fmt.Errorf("unable to parse cilium version on pod %q: %w", name, err)
}
if minVersion == nil || podVersion.LT(*minVersion) {
minVersion = &podVersion
}
}

return minVersion, nil
}

func (ct *ConnectivityTest) RandomClientPod() *Pod {
for _, p := range ct.clientPods {
return &p
Expand Down
6 changes: 3 additions & 3 deletions connectivity/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ func Run(ctx context.Context, ct *check.ConnectivityTest) error {
if err != nil {
return err
}
} else if helmState, err := ct.K8sClient().GetHelmState(ctx, ct.Params().CiliumNamespace, defaults.HelmValuesSecretName); err != nil {
ct.Warnf("Unable to detect Cilium version, assuming %v for connectivity tests", defaults.Version)
} else if minVersion, err := ct.DetectMinimumCiliumVersion(ctx); err != nil {
ct.Warnf("Unable to detect Cilium version, assuming %v for connectivity tests: %s", defaults.Version, err)
v, err = utils.ParseCiliumVersion(defaults.Version)
if err != nil {
return err
}
} else {
v = helmState.Version
v = *minVersion
}

ct.Infof("Cilium version: %v", v)
Expand Down