-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(install): Probe KubeArmor after installing to show enforcement i…
…s enabled or not Signed-off-by: daemon1024 <barun1024@gmail.com>
- Loading branch information
1 parent
3eaffba
commit 986605e
Showing
3 changed files
with
161 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package k8s | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
"golang.org/x/mod/semver" | ||
) | ||
|
||
// AutoDetectEnvironment detect the environment for a given k8s context | ||
func AutoDetectEnvironment(c *Client) (name string) { | ||
env := "none" | ||
|
||
contextName := c.RawConfig.CurrentContext | ||
clusterContext, exists := c.RawConfig.Contexts[contextName] | ||
if !exists { | ||
return env | ||
} | ||
|
||
clusterName := clusterContext.Cluster | ||
cluster := c.RawConfig.Clusters[clusterName] | ||
nodes, _ := c.K8sClientset.CoreV1().Nodes().List(context.Background(), metav1.ListOptions{}) | ||
if len(nodes.Items) <= 0 { | ||
return env | ||
} | ||
containerRuntime := nodes.Items[0].Status.NodeInfo.ContainerRuntimeVersion | ||
nodeImage := nodes.Items[0].Status.NodeInfo.OSImage | ||
|
||
// Detecting Environment based on cluster name and context or OSImage | ||
if clusterName == "minikube" || contextName == "minikube" { | ||
env = "minikube" | ||
return env | ||
} | ||
|
||
if strings.HasPrefix(clusterName, "microk8s-") || contextName == "microk8s" { | ||
env = "microk8s" | ||
return env | ||
} | ||
|
||
if strings.HasPrefix(clusterName, "gke_") { | ||
env = "gke" | ||
return env | ||
} | ||
|
||
if strings.Contains(nodeImage, "Bottlerocket") { | ||
env = "bottlerocket" | ||
return env | ||
} | ||
|
||
if strings.HasSuffix(clusterName, ".eksctl.io") || strings.HasSuffix(cluster.Server, "eks.amazonaws.com") { | ||
env = "eks" | ||
return env | ||
} | ||
|
||
// Environment is Self Managed K8s, checking container runtime and it's version | ||
|
||
if strings.Contains(containerRuntime, "k3s") { | ||
env = "k3s" | ||
return env | ||
} | ||
|
||
s := strings.Split(containerRuntime, "://") | ||
runtime := s[0] | ||
version := "v" + s[1] | ||
|
||
if runtime == "docker" && semver.Compare(version, "v18.9") >= 0 { | ||
env = "docker" | ||
return env | ||
} | ||
|
||
if runtime == "cri-o" { | ||
env = "oke" | ||
return env | ||
} | ||
|
||
if (runtime == "docker" && semver.Compare(version, "v19.3") >= 0) || runtime == "containerd" { | ||
env = "generic" | ||
return env | ||
} | ||
|
||
return env | ||
} |
Oops, something went wrong.