Skip to content
This repository has been archived by the owner on Oct 30, 2024. It is now read-only.

Commit

Permalink
Merge pull request #38 from Shopify/types
Browse files Browse the repository at this point in the history
 types: Create internal types instead of using kubernetes types
  • Loading branch information
jinankjain authored Oct 19, 2017
2 parents 2a62c1f + cf98fca commit a9f5bcd
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 70 deletions.
3 changes: 1 addition & 2 deletions cmd/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
apiv1 "k8s.io/api/core/v1"
)

var imgConfig imgFlags
Expand Down Expand Up @@ -54,7 +53,7 @@ func printResultImg(results []Result) {
}
}

func checkImage(container apiv1.Container, image imgFlags, result *Result) {
func checkImage(container Container, image imgFlags, result *Result) {
image.splitImageString()
contImage := imgFlags{img: container.Image}
contImage.splitImageString()
Expand Down
29 changes: 13 additions & 16 deletions cmd/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ import (
"os"

log "github.com/sirupsen/logrus"
appsv1beta1 "k8s.io/api/apps/v1beta1"
apiv1 "k8s.io/api/core/v1"
extensionsv1beta1 "k8s.io/api/extensions/v1beta1"
networking "k8s.io/api/networking/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/pkg/version"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp" // auth for GKE clusters
Expand Down Expand Up @@ -48,54 +45,54 @@ func kubeClient(kubeconfig string) (*kubernetes.Clientset, error) {
return kube, err
}

func getNamespaces(clientset *kubernetes.Clientset) *apiv1.NamespaceList {
func getNamespaces(clientset *kubernetes.Clientset) *NamespaceList {
namespaceClient := clientset.Namespaces()
namespaces, err := namespaceClient.List(metav1.ListOptions{})
namespaces, err := namespaceClient.List(ListOptions{})
if err != nil {
log.Error(err)
}
return namespaces
}

func getDeployments(clientset *kubernetes.Clientset) *appsv1beta1.DeploymentList {
func getDeployments(clientset *kubernetes.Clientset) *DeploymentList {
deploymentClient := clientset.AppsV1beta1().Deployments(apiv1.NamespaceAll)
deployments, err := deploymentClient.List(metav1.ListOptions{})
deployments, err := deploymentClient.List(ListOptions{})
if err != nil {
log.Error(err)
}
return deployments
}

func getStatefulSets(clientset *kubernetes.Clientset) *appsv1beta1.StatefulSetList {
func getStatefulSets(clientset *kubernetes.Clientset) *StatefulSetList {
statefulSetClient := clientset.AppsV1beta1().StatefulSets(apiv1.NamespaceAll)
statefulSets, err := statefulSetClient.List(metav1.ListOptions{})
statefulSets, err := statefulSetClient.List(ListOptions{})
if err != nil {
log.Error(err)
}
return statefulSets
}

func getDaemonSets(clientset *kubernetes.Clientset) *extensionsv1beta1.DaemonSetList {
func getDaemonSets(clientset *kubernetes.Clientset) *DaemonSetList {
daemonSetClient := clientset.ExtensionsV1beta1().DaemonSets(apiv1.NamespaceAll)
daemonSets, err := daemonSetClient.List(metav1.ListOptions{})
daemonSets, err := daemonSetClient.List(ListOptions{})
if err != nil {
log.Error(err)
}
return daemonSets
}

func getPods(clientset *kubernetes.Clientset) *apiv1.PodList {
func getPods(clientset *kubernetes.Clientset) *PodList {
podClient := clientset.Pods(apiv1.NamespaceAll)
pods, err := podClient.List(metav1.ListOptions{})
pods, err := podClient.List(ListOptions{})
if err != nil {
log.Error(err)
}
return pods
}

func getReplicationControllers(clientset *kubernetes.Clientset) *apiv1.ReplicationControllerList {
func getReplicationControllers(clientset *kubernetes.Clientset) *ReplicationControllerList {
replicationControllerClient := clientset.ReplicationControllers(apiv1.NamespaceAll)
replicationControllers, err := replicationControllerClient.List(metav1.ListOptions{})
replicationControllers, err := replicationControllerClient.List(ListOptions{})
if err != nil {
log.Error(err)
}
Expand All @@ -104,7 +101,7 @@ func getReplicationControllers(clientset *kubernetes.Clientset) *apiv1.Replicati

func getNetworkPolicies(clientset *kubernetes.Clientset) *networking.NetworkPolicyList {
netPolClient := clientset.NetworkPolicies(apiv1.NamespaceAll)
netPols, err := netPolClient.List(metav1.ListOptions{})
netPols, err := netPolClient.List(ListOptions{})
if err != nil {
log.Error(err)
}
Expand Down
5 changes: 2 additions & 3 deletions cmd/networkPolicies.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ package cmd
import (
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
networking "k8s.io/api/networking/v1"
)

func checkNamespaceNetworkPolicies(netPols *networking.NetworkPolicyList) {
badNetPols := []networking.NetworkPolicy{}
func checkNamespaceNetworkPolicies(netPols *NetworkPolicyList) {
badNetPols := []NetworkPolicy{}

for _, netPol := range netPols.Items {
for _, ingress := range netPol.Spec.Ingress {
Expand Down
3 changes: 1 addition & 2 deletions cmd/privileged.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cmd
import (
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
apiv1 "k8s.io/api/core/v1"
)

func printResultPrivileged(results []Result) {
Expand All @@ -14,7 +13,7 @@ func printResultPrivileged(results []Result) {
}
}

func checkPrivileged(container apiv1.Container, result *Result) {
func checkPrivileged(container Container, result *Result) {
if container.SecurityContext != nil {
if container.SecurityContext.Privileged != nil && *container.SecurityContext.Privileged {
result.err = 1
Expand Down
3 changes: 1 addition & 2 deletions cmd/readOnlyRootFilesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cmd
import (
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
apiv1 "k8s.io/api/core/v1"
)

func printResultRFS(results []Result) {
Expand Down Expand Up @@ -31,7 +30,7 @@ func printResultRFS(results []Result) {
}
}

func checkReadOnlyRootFS(container apiv1.Container, result *Result) {
func checkReadOnlyRootFS(container Container, result *Result) {
if container.SecurityContext == nil {
result.err = ErrorSecurityContextNIL
return
Expand Down
3 changes: 1 addition & 2 deletions cmd/runAsNonRoot.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cmd
import (
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
apiv1 "k8s.io/api/core/v1"
)

func printResultNR(results []Result) {
Expand Down Expand Up @@ -31,7 +30,7 @@ func printResultNR(results []Result) {
}
}

func checkRunAsNonRoot(container apiv1.Container, result *Result) {
func checkRunAsNonRoot(container Container, result *Result) {
if container.SecurityContext == nil {
result.err = ErrorSecurityContextNIL
return
Expand Down
3 changes: 1 addition & 2 deletions cmd/securityContext.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import (

log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
apiv1 "k8s.io/api/core/v1"
)

func checkSecurityContext(container apiv1.Container, result *Result) {
func checkSecurityContext(container Container, result *Result) {
if container.SecurityContext == nil {
result.err = ErrorSecurityContextNIL
return
Expand Down
28 changes: 28 additions & 0 deletions cmd/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package cmd

import (
v1beta1 "k8s.io/api/apps/v1beta1"
apiv1 "k8s.io/api/core/v1"
extensionsv1beta1 "k8s.io/api/extensions/v1beta1"
networking "k8s.io/api/networking/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type Pod = apiv1.Pod
type ReplicationController = apiv1.ReplicationController
type DaemonSet = extensionsv1beta1.DaemonSet
type Deployment = v1beta1.Deployment
type StatefulSet = v1beta1.StatefulSet
type NetworkPolicy = networking.NetworkPolicy

type PodList = apiv1.PodList
type ReplicationControllerList = apiv1.ReplicationControllerList
type DaemonSetList = extensionsv1beta1.DaemonSetList
type DeploymentList = v1beta1.DeploymentList
type StatefulSetList = v1beta1.StatefulSetList
type NamespaceList = apiv1.NamespaceList
type NetworkPolicyList = networking.NetworkPolicyList

type Capability = apiv1.Capability
type Container = apiv1.Container
type ListOptions = metav1.ListOptions
Loading

0 comments on commit a9f5bcd

Please sign in to comment.