Skip to content

Commit

Permalink
import optimization (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
testwill authored May 14, 2023
1 parent bbbe80c commit 1f563a0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
5 changes: 2 additions & 3 deletions pkg/jobs/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/aquasecurity/trivy-kubernetes/pkg/k8s"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
k8sapierror "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down Expand Up @@ -200,7 +199,7 @@ func (jb *jobCollector) ApplyAndCollect(ctx context.Context, nodeName string) (s
_, err = jb.getTrivyNamespace(ctx)
if err != nil {
if k8sapierror.IsNotFound(err) {
trivyNamespace := &v1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: jb.namespace}}
trivyNamespace := &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: jb.namespace}}
_, err = jb.cluster.GetK8sClientSet().CoreV1().Namespaces().Create(ctx, trivyNamespace, metav1.CreateOptions{})
if err != nil {
return "", err
Expand Down Expand Up @@ -268,7 +267,7 @@ func (jb *jobCollector) deleteTrivyNamespace(ctx context.Context) {
})
}

func (jb *jobCollector) getTrivyNamespace(ctx context.Context) (*v1.Namespace, error) {
func (jb *jobCollector) getTrivyNamespace(ctx context.Context) (*corev1.Namespace, error) {
return jb.cluster.GetK8sClientSet().CoreV1().Namespaces().Get(ctx, jb.namespace, metav1.GetOptions{})
}

Expand Down
6 changes: 2 additions & 4 deletions pkg/k8s/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ import (
"strings"

"github.com/aquasecurity/trivy-kubernetes/pkg/bom"
"github.com/google/go-containerregistry/pkg/name"
containerimage "github.com/google/go-containerregistry/pkg/name"
corev1 "k8s.io/api/core/v1"
k8sapierror "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/client-go/dynamic"
Expand Down Expand Up @@ -225,7 +223,7 @@ func IsClusterResource(gvr schema.GroupVersionResource) bool {

// IsBuiltInWorkload returns true if the specified v1.OwnerReference
// is a built-in Kubernetes workload, false otherwise.
func IsBuiltInWorkload(resource *v1.OwnerReference) bool {
func IsBuiltInWorkload(resource *metav1.OwnerReference) bool {
return resource != nil &&
(resource.Kind == string(KindReplicaSet) ||
resource.Kind == string(KindReplicationController) ||
Expand Down Expand Up @@ -299,7 +297,7 @@ func (c *cluster) CreateClusterBom(ctx context.Context) (*bom.Result, error) {
return c.getClusterBomInfo(components, nodesInfo)
}

func (c *cluster) GetBaseComponent(imageRef name.Reference, imageName name.Reference) (bom.Component, error) {
func (c *cluster) GetBaseComponent(imageRef containerimage.Reference, imageName containerimage.Reference) (bom.Component, error) {
repoName := imageRef.Context().RepositoryStr()
registryName := imageRef.Context().RegistryStr()
if strings.HasPrefix(repoName, "library/sha256") {
Expand Down

0 comments on commit 1f563a0

Please sign in to comment.