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

sysdump feature detection: Don't depend on Cilium version #2032

Merged
merged 1 commit into from
Oct 12, 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
3 changes: 2 additions & 1 deletion connectivity/check/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,8 @@ func (ct *ConnectivityTest) detectFeatures(ctx context.Context) error {
// If unsure from which source to retrieve the information from,
// prefer "CiliumStatus" over "ConfigMap" over "RuntimeConfig".
// See the corresponding functions for more information.
features.ExtractFromConfigMap(ct.CiliumVersion, cm)
features.ExtractFromVersionedConfigMap(ct.CiliumVersion, cm)
features.ExtractFromConfigMap(cm)
err = ct.extractFeaturesFromRuntimeConfig(ctx, ciliumPod, features)
if err != nil {
return err
Expand Down
8 changes: 2 additions & 6 deletions sysdump/sysdump.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,8 @@ func NewCollector(k KubernetesClient, o Options, startTime time.Time, cliVersion
}
c.log("ℹ️ %s ConfigMap not found in %s namespace", ciliumConfigMapName, c.Options.CiliumNamespace)
}
if c.CiliumConfigMap != nil && len(c.CiliumPods) > 0 {
ciliumVersion, err := c.Client.GetCiliumVersion(context.Background(), c.CiliumPods[0])
if err != nil {
return nil, fmt.Errorf("failed to get Cilium version from %s/%s: %w", c.CiliumPods[0].Namespace, c.CiliumPods[0].Name, err)
}
c.FeatureSet.ExtractFromConfigMap(*ciliumVersion, c.CiliumConfigMap)
if c.CiliumConfigMap != nil {
c.FeatureSet.ExtractFromConfigMap(c.CiliumConfigMap)
c.log("🔮 Detected Cilium features: %v", c.FeatureSet)
}
}
Expand Down
40 changes: 22 additions & 18 deletions utils/features/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,24 +177,11 @@ func RequireMode(feature Feature, mode string) Requirement {
}
}

// extractFeaturesFromConfigMap extracts features from the Cilium ConfigMap.
// Note that there is no rule regarding if the default value is reflected
// in the ConfigMap or not.
func (fs Set) ExtractFromConfigMap(ciliumVersion semver.Version, cm *v1.ConfigMap) {
// CNI chaining.
// Note: This value might be overwritten by extractFeaturesFromCiliumStatus
// if this information is present in `cilium status`
mode := "none"
if v, ok := cm.Data["cni-chaining-mode"]; ok {
mode = v
}
fs[CNIChaining] = Status{
Enabled: mode != "none",
Mode: mode,
}

// ExtractFromVersionedConfigMap extracts features based on Cilium version and cilium-config
// ConfigMap.
func (fs Set) ExtractFromVersionedConfigMap(ciliumVersion semver.Version, cm *v1.ConfigMap) {
if versioncheck.MustCompile("<1.14.0")(ciliumVersion) {
mode = "vxlan"
mode := "vxlan"
if v, ok := cm.Data["tunnel"]; ok {
mode = v
}
Expand All @@ -203,7 +190,7 @@ func (fs Set) ExtractFromConfigMap(ciliumVersion semver.Version, cm *v1.ConfigMa
Mode: mode,
}
} else {
mode = "tunnel"
mode := "tunnel"
if v, ok := cm.Data["routing-mode"]; ok {
mode = v
}
Expand All @@ -220,6 +207,23 @@ func (fs Set) ExtractFromConfigMap(ciliumVersion semver.Version, cm *v1.ConfigMa
Mode: tunnelProto,
}
}
}

// ExtractFromConfigMap extracts features from the Cilium ConfigMap.
// Note that there is no rule regarding if the default value is reflected
// in the ConfigMap or not.
func (fs Set) ExtractFromConfigMap(cm *v1.ConfigMap) {
// CNI chaining.
// Note: This value might be overwritten by extractFeaturesFromCiliumStatus
// if this information is present in `cilium status`
mode := "none"
if v, ok := cm.Data["cni-chaining-mode"]; ok {
mode = v
}
fs[CNIChaining] = Status{
Enabled: mode != "none",
Mode: mode,
}

fs[IPv4] = Status{
Enabled: cm.Data["enable-ipv4"] == "true",
Expand Down
23 changes: 16 additions & 7 deletions utils/features/features_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,33 @@ func TestFeatureSetMatchRequirements(t *testing.T) {
}
}

func TestFeatureSet_extractFeaturesFromConfigMap(t *testing.T) {
func TestFeatureSet_extractFromVersionedConfigMap(t *testing.T) {
fs := Set{}
ciliumVersion := semver.Version{Major: 1, Minor: 14, Patch: 0}
cm := corev1.ConfigMap{}
fs.ExtractFromConfigMap(ciliumVersion, &cm)
fs.ExtractFromVersionedConfigMap(ciliumVersion, &cm)
cm.Data = map[string]string{
"routing-mode": "tunnel",
"tunnel-protocol": "geneve",
}
fs.ExtractFromVersionedConfigMap(ciliumVersion, &cm)
assert.True(t, fs[Tunnel].Enabled)
assert.Equal(t, "geneve", fs[Tunnel].Mode)
}

func TestFeatureSet_extractFromConfigMap(t *testing.T) {
fs := Set{}
cm := corev1.ConfigMap{}
fs.ExtractFromConfigMap(&cm)
cm.Data = map[string]string{
"enable-ipv4": "true",
"enable-ipv6": "true",
"routing-mode": "tunnel",
"tunnel-protocol": "geneve",
"mesh-auth-mutual-enabled": "true",
"enable-ipv4-egress-gateway": "true",
}
fs.ExtractFromConfigMap(ciliumVersion, &cm)
fs.ExtractFromConfigMap(&cm)
assert.True(t, fs[IPv4].Enabled)
assert.True(t, fs[IPv6].Enabled)
assert.True(t, fs[AuthSpiffe].Enabled)
assert.True(t, fs[EgressGateway].Enabled)
assert.True(t, fs[Tunnel].Enabled)
assert.Equal(t, "geneve", fs[Tunnel].Mode)
}