Skip to content

Commit

Permalink
fix: add k8s component label (#231)
Browse files Browse the repository at this point in the history
Signed-off-by: chenk <[email protected]>
  • Loading branch information
chen-keinan authored Sep 28, 2023
1 parent 952766b commit 9200a44
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions pkg/k8s/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
//"k8s.io/apimachinery/pkg/version"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/kubernetes"
Expand Down Expand Up @@ -43,6 +42,13 @@ var (
"etcd": "etcd/v3",
"secrets-store-csi-driver": "secrets-store-csi-driver",
}
CoreComponentPropertyType = map[string]string{
"controller-manager": "controlPlane",
"apiserver": "controlPlane",
"kube-scheduler": "controlPlane",
"etcd/v3": "controlPlane",
"kube-proxy": "node",
}
)

const (
Expand Down Expand Up @@ -322,7 +328,7 @@ func (c *cluster) CreateClusterBom(ctx context.Context) (*bom.Result, error) {
"openshift-etcd": "etcd",
}
}
components, err := c.collectComponents(ctx, labels, "ControlPlane")
components, err := c.collectComponents(ctx, labels)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -410,7 +416,7 @@ func getPodsInfo(ctx context.Context, clientset *kubernetes.Clientset, labelSele
return pods, nil
}

func (c *cluster) collectComponents(ctx context.Context, labels map[string]string, propertyKey ...string) ([]bom.Component, error) {
func (c *cluster) collectComponents(ctx context.Context, labels map[string]string) ([]bom.Component, error) {
components := make([]bom.Component, 0)
for namespace, labelSelector := range labels {
pods, err := getPodsInfo(ctx, c.clientset, labelSelector, namespace)
Expand Down Expand Up @@ -443,10 +449,11 @@ func (c *cluster) collectComponents(ctx context.Context, labels map[string]strin
if ok {
props["Name"] = pod.Name
}
if len(propertyKey) > 0 {
props["Type"] = propertyKey[0]
}

repoName := upstreamRepoByName(componentValue)
if val, ok := CoreComponentPropertyType[repoName]; ok {
props["Type"] = val
}
orgName := upstreamOrgByName(repoName)
upstreamComponentName := repoName
if len(orgName) > 0 {
Expand Down Expand Up @@ -490,7 +497,7 @@ func (c *cluster) getClusterBomInfo(components []bom.Component, nodeInfo []bom.N
ID: "k8s.io/kubernetes",
Type: "Cluster",
Version: trimString(version, []string{"v", "V"}),
Properties: map[string]string{"Name": name},
Properties: map[string]string{"Name": name, "Type": "cluster"},
NodesInfo: nodeInfo,
}
return br, nil
Expand Down

0 comments on commit 9200a44

Please sign in to comment.