Skip to content

Commit

Permalink
fix: added kind and apiversion to single workload results.
Browse files Browse the repository at this point in the history
  • Loading branch information
beneiltis committed Sep 10, 2024
1 parent 25e72cc commit 3f0af5b
Show file tree
Hide file tree
Showing 36 changed files with 230 additions and 52 deletions.
2 changes: 2 additions & 0 deletions kubernetes/certificates.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ func GetCertificate(namespaceName string, resourceName string, contextId *string
return nil, err
}
certificate, err := provider.ClientSet.CertmanagerV1().Certificates(namespaceName).Get(context.TODO(), resourceName, metav1.GetOptions{})
certificate.Kind = "Certificate"
certificate.APIVersion = "cert-manager.io/v1"
if err != nil {
logger.Log.Errorf("GetCertificate ERROR: %s", err.Error())
return nil, err
Expand Down
6 changes: 5 additions & 1 deletion kubernetes/cluster-role-bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ func GetClusterRoleBinding(name string, contextId *string) (*v1.ClusterRoleBindi
if err != nil {
return nil, err
}
return provider.ClientSet.RbacV1().ClusterRoleBindings().Get(context.TODO(), name, metav1.GetOptions{})
role, err := provider.ClientSet.RbacV1().ClusterRoleBindings().Get(context.TODO(), name, metav1.GetOptions{})
role.Kind = "ClusterRoleBinding"
role.APIVersion = "rbac.authorization.k8s.io/v1"

return role, err
}

func UpdateK8sClusterRoleBinding(data v1.ClusterRoleBinding, contextId *string) utils.K8sWorkloadResult {
Expand Down
6 changes: 5 additions & 1 deletion kubernetes/cluster-roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ func GetClusterRole(name string, contextId *string) (*v1.ClusterRole, error) {
if err != nil {
return nil, err
}
return provider.ClientSet.RbacV1().ClusterRoles().Get(context.TODO(), name, metav1.GetOptions{})
role, err := provider.ClientSet.RbacV1().ClusterRoles().Get(context.TODO(), name, metav1.GetOptions{})
role.Kind = "ClusterRole"
role.APIVersion = "rbac.authorization.k8s.io/v1"

return role, err
}

func UpdateK8sClusterRole(data v1.ClusterRole, contextId *string) utils.K8sWorkloadResult {
Expand Down
5 changes: 4 additions & 1 deletion kubernetes/clusterIssuer.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ func GetClusterIssuer(name string, contextId *string) (*cmapi.ClusterIssuer, err
if err != nil {
return nil, err
}
return provider.ClientSet.CertmanagerV1().ClusterIssuers().Get(context.TODO(), name, metav1.GetOptions{})
issuer, err := provider.ClientSet.CertmanagerV1().ClusterIssuers().Get(context.TODO(), name, metav1.GetOptions{})
issuer.Kind = "ClusterIssuer"
issuer.APIVersion = "cert-manager.io/v1"
return issuer, err
}

func UpdateK8sClusterIssuer(data cmapi.ClusterIssuer, contextId *string) utils.K8sWorkloadResult {
Expand Down
8 changes: 7 additions & 1 deletion kubernetes/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ func ConfigMapFor(namespace string, configMapName string, showError bool, contex
}
return nil
}
configMap.Kind = "ConfigMap"
configMap.APIVersion = "v1"
return configMap
}

Expand Down Expand Up @@ -79,7 +81,11 @@ func GetK8sConfigmap(namespaceName string, name string, contextId *string) (*v1.
if err != nil {
return nil, err
}
return provider.ClientSet.CoreV1().ConfigMaps(namespaceName).Get(context.TODO(), name, metav1.GetOptions{})
configmap, err := provider.ClientSet.CoreV1().ConfigMaps(namespaceName).Get(context.TODO(), name, metav1.GetOptions{})
configmap.Kind = "ConfigMap"
configmap.APIVersion = "v1"

return configmap, err
}

func UpdateK8sConfigMap(data v1.ConfigMap, contextId *string) utils.K8sWorkloadResult {
Expand Down
6 changes: 5 additions & 1 deletion kubernetes/cronjobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ func GetCronjob(namespaceName string, name string, contextId *string) (*v1.CronJ
if err != nil {
return nil, err
}
return provider.ClientSet.BatchV1().CronJobs(namespaceName).Get(context.TODO(), name, metav1.GetOptions{})
cronjob, err := provider.ClientSet.BatchV1().CronJobs(namespaceName).Get(context.TODO(), name, metav1.GetOptions{})
cronjob.Kind = "CronJob"
cronjob.APIVersion = "batch/v1"

return cronjob, err
}

func UpdateK8sCronJob(data v1.CronJob, contextId *string) utils.K8sWorkloadResult {
Expand Down
6 changes: 5 additions & 1 deletion kubernetes/csr.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ func GetCertificateSigningRequest(namespaceName string, name string, contextId *
if err != nil {
return nil, err
}
return provider.ClientSet.CertmanagerV1().CertificateRequests(namespaceName).Get(context.TODO(), name, metav1.GetOptions{})
certificate, err := provider.ClientSet.CertmanagerV1().CertificateRequests(namespaceName).Get(context.TODO(), name, metav1.GetOptions{})
certificate.Kind = "CertificateSigningRequest"
certificate.APIVersion = "cert-manager.io/v1"

return certificate, nil
}

func UpdateK8sCertificateSigningRequest(data cmapi.CertificateRequest, contextId *string) utils.K8sWorkloadResult {
Expand Down
6 changes: 5 additions & 1 deletion kubernetes/daemonsets.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ func GetK8sDaemonset(namespaceName string, name string, contextId *string) (*v1.
if err != nil {
return nil, err
}
return provider.ClientSet.AppsV1().DaemonSets(namespaceName).Get(context.TODO(), name, metav1.GetOptions{})
daemonset, err := provider.ClientSet.AppsV1().DaemonSets(namespaceName).Get(context.TODO(), name, metav1.GetOptions{})
daemonset.Kind = "DaemonSet"
daemonset.APIVersion = "apps/v1"

return daemonset, err
}

func UpdateK8sDaemonSet(data v1.DaemonSet, contextId *string) utils.K8sWorkloadResult {
Expand Down
6 changes: 5 additions & 1 deletion kubernetes/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ func GetK8sDeployment(namespaceName string, name string, contextId *string) (*v1
if err != nil {
return nil, err
}
return provider.ClientSet.AppsV1().Deployments(namespaceName).Get(context.TODO(), name, metav1.GetOptions{})
deployment, err := provider.ClientSet.AppsV1().Deployments(namespaceName).Get(context.TODO(), name, metav1.GetOptions{})
deployment.Kind = "Deployment"
deployment.APIVersion = "apps/v1"

return deployment, err
}

func UpdateK8sDeployment(data v1.Deployment, contextId *string) utils.K8sWorkloadResult {
Expand Down
6 changes: 5 additions & 1 deletion kubernetes/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ func GetEndpoint(namespaceName string, name string, contextId *string) (*corev1.
if err != nil {
return nil, err
}
return provider.ClientSet.CoreV1().Endpoints(namespaceName).Get(context.TODO(), name, metav1.GetOptions{})
endpoint, err := provider.ClientSet.CoreV1().Endpoints(namespaceName).Get(context.TODO(), name, metav1.GetOptions{})
endpoint.Kind = "Endpoints"
endpoint.APIVersion = "v1"

return endpoint, err
}

func UpdateK8sEndpoint(data corev1.Endpoints, contextId *string) utils.K8sWorkloadResult {
Expand Down
6 changes: 5 additions & 1 deletion kubernetes/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ func GetEvent(namespaceName string, name string, contextId *string) (*v1Core.Eve
if err != nil {
return nil, err
}
return provider.ClientSet.CoreV1().Events(namespaceName).Get(context.TODO(), name, metav1.GetOptions{})
event, err := provider.ClientSet.CoreV1().Events(namespaceName).Get(context.TODO(), name, metav1.GetOptions{})
event.Kind = "Event"
event.APIVersion = "v1"

return event, err
}

func DescribeK8sEvent(namespace string, name string, contextId *string) utils.K8sWorkloadResult {
Expand Down
6 changes: 5 additions & 1 deletion kubernetes/hpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ func GetHpa(namespaceName string, name string, contextId *string) (*v2.Horizonta
if err != nil {
return nil, err
}
return provider.ClientSet.AutoscalingV2().HorizontalPodAutoscalers(namespaceName).Get(context.TODO(), name, metav1.GetOptions{})
hpa, err := provider.ClientSet.AutoscalingV2().HorizontalPodAutoscalers(namespaceName).Get(context.TODO(), name, metav1.GetOptions{})
hpa.Kind = "HorizontalPodAutoscaler"
hpa.APIVersion = "autoscaling/v2"

return hpa, err
}

func UpdateK8sHpa(data v2.HorizontalPodAutoscaler, contextId *string) utils.K8sWorkloadResult {
Expand Down
6 changes: 5 additions & 1 deletion kubernetes/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ func GetK8sIngress(namespaceName string, name string, contextId *string) (*v1.In
if err != nil {
return nil, err
}
return provider.ClientSet.NetworkingV1().Ingresses(namespaceName).Get(context.TODO(), name, metav1.GetOptions{})
ingress, err := provider.ClientSet.NetworkingV1().Ingresses(namespaceName).Get(context.TODO(), name, metav1.GetOptions{})
ingress.Kind = "Ingress"
ingress.APIVersion = "networking.k8s.io/v1"

return ingress, err
}

func UpdateK8sIngress(data v1.Ingress, contextId *string) utils.K8sWorkloadResult {
Expand Down
6 changes: 5 additions & 1 deletion kubernetes/ingressClass.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ func GetK8sIngressClass(name string, contextId *string) (*v1.IngressClass, error
if err != nil {
return nil, err
}
return provider.ClientSet.NetworkingV1().IngressClasses().Get(context.TODO(), name, metav1.GetOptions{})
ingress, err := provider.ClientSet.NetworkingV1().IngressClasses().Get(context.TODO(), name, metav1.GetOptions{})
ingress.Kind = "IngressClass"
ingress.APIVersion = "networking.k8s.io/v1"

return ingress, err
}

func UpdateK8sIngressClass(data v1.IngressClass, contextId *string) utils.K8sWorkloadResult {
Expand Down
6 changes: 5 additions & 1 deletion kubernetes/issuer.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ func GetIssuer(namespaceName string, name string, contextId *string) (*cmapi.Iss
if err != nil {
return nil, err
}
return provider.ClientSet.CertmanagerV1().Issuers(namespaceName).Get(context.TODO(), name, metav1.GetOptions{})
issuer, err := provider.ClientSet.CertmanagerV1().Issuers(namespaceName).Get(context.TODO(), name, metav1.GetOptions{})
issuer.Kind = "Issuer"
issuer.APIVersion = "cert-manager.io/v1"

return issuer, err
}

func UpdateK8sIssuer(data cmapi.Issuer, contextId *string) utils.K8sWorkloadResult {
Expand Down
6 changes: 5 additions & 1 deletion kubernetes/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ func GetJob(namespaceName string, name string, contextId *string) (*v1job.Job, e
if err != nil {
return nil, err
}
return provider.ClientSet.BatchV1().Jobs(namespaceName).Get(context.TODO(), name, metav1.GetOptions{})
job, err := provider.ClientSet.BatchV1().Jobs(namespaceName).Get(context.TODO(), name, metav1.GetOptions{})
job.Kind = "Job"
job.APIVersion = "batch/v1"

return job, err
}

func UpdateK8sJob(data v1job.Job, contextId *string) utils.K8sWorkloadResult {
Expand Down
30 changes: 17 additions & 13 deletions kubernetes/leases.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ func AllLeases(namespaceName string, contextId *string) []v1.Lease {
if err != nil {
return result
}
rolesList, err := provider.ClientSet.CoordinationV1().Leases(namespaceName).List(context.TODO(), metav1.ListOptions{})
leaseList, err := provider.ClientSet.CoordinationV1().Leases(namespaceName).List(context.TODO(), metav1.ListOptions{})
if err != nil {
logger.Log.Errorf("AllLeases ERROR: %s", err.Error())
return result
}

for _, role := range rolesList.Items {
if !utils.Contains(utils.CONFIG.Misc.IgnoreNamespaces, role.ObjectMeta.Namespace) {
role.Kind = "Lease"
role.APIVersion = "coordination.k8s.io/v1"
result = append(result, role)
for _, lease := range leaseList.Items {
if !utils.Contains(utils.CONFIG.Misc.IgnoreNamespaces, lease.ObjectMeta.Namespace) {
lease.Kind = "Lease"
lease.APIVersion = "coordination.k8s.io/v1"
result = append(result, lease)
}
}
return result
Expand All @@ -43,17 +43,17 @@ func AllK8sLeases(namespaceName string, contextId *string) utils.K8sWorkloadResu
if err != nil {
return WorkloadResult(nil, err)
}
rolesList, err := provider.ClientSet.CoordinationV1().Leases(namespaceName).List(context.TODO(), metav1.ListOptions{})
leaseList, err := provider.ClientSet.CoordinationV1().Leases(namespaceName).List(context.TODO(), metav1.ListOptions{})
if err != nil {
logger.Log.Errorf("AllLeases ERROR: %s", err.Error())
return WorkloadResult(nil, err)
}

for _, role := range rolesList.Items {
if !utils.Contains(utils.CONFIG.Misc.IgnoreNamespaces, role.ObjectMeta.Namespace) {
role.Kind = "Lease"
role.APIVersion = "coordination.k8s.io/v1"
result = append(result, role)
for _, lease := range leaseList.Items {
if !utils.Contains(utils.CONFIG.Misc.IgnoreNamespaces, lease.ObjectMeta.Namespace) {
lease.Kind = "Lease"
lease.APIVersion = "coordination.k8s.io/v1"
result = append(result, lease)
}
}
return WorkloadResult(result, nil)
Expand All @@ -64,7 +64,11 @@ func GetLeas(namespaceName string, name string, contextId *string) (*v1.Lease, e
if err != nil {
return nil, err
}
return provider.ClientSet.CoordinationV1().Leases(namespaceName).Get(context.TODO(), name, metav1.GetOptions{})
lease, err := provider.ClientSet.CoordinationV1().Leases(namespaceName).Get(context.TODO(), name, metav1.GetOptions{})
lease.Kind = "Lease"
lease.APIVersion = "coordination.k8s.io/v1"

return lease, err
}

func UpdateK8sLease(data v1.Lease, contextId *string) utils.K8sWorkloadResult {
Expand Down
6 changes: 5 additions & 1 deletion kubernetes/networkpolicies.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ func GetNetworkPolicy(namespaceName string, name string, contextId *string) (*v1
if err != nil {
return nil, err
}
return provider.ClientSet.NetworkingV1().NetworkPolicies(namespaceName).Get(context.TODO(), name, metav1.GetOptions{})
netpol, err := provider.ClientSet.NetworkingV1().NetworkPolicies(namespaceName).Get(context.TODO(), name, metav1.GetOptions{})
netpol.Kind = "NetworkPolicy"
netpol.APIVersion = "networking.k8s.io/v1"

return netpol, err
}

func UpdateK8sNetworkPolicy(data v1.NetworkPolicy, contextId *string) utils.K8sWorkloadResult {
Expand Down
15 changes: 13 additions & 2 deletions kubernetes/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ func SumCpuResources(pods []v1.Pod) (request float64, limit float64) {
}

func ListK8sNodes(contextId *string) utils.K8sWorkloadResult {
result := []v1.Node{}

provider, err := NewKubeProvider(contextId)
if provider == nil || err != nil {
err := fmt.Errorf("failed to load provider")
Expand All @@ -137,15 +139,24 @@ func ListK8sNodes(contextId *string) utils.K8sWorkloadResult {
logger.Log.Errorf("ListNodeMetrics ERROR: %s", err.Error())
return WorkloadResult(nil, err)
}
return WorkloadResult(nodeMetricsList.Items, nil)
for _, v := range nodeMetricsList.Items {
v.Kind = "Node"
v.APIVersion = "v1"
result = append(result, v)
}

return WorkloadResult(result, nil)
}

func GetK8sNode(name string, contextId *string) (*v1.Node, error) {
provider, err := NewKubeProvider(contextId)
if err != nil {
return nil, err
}
return provider.ClientSet.CoreV1().Nodes().Get(context.TODO(), name, metav1.GetOptions{})
node, err := provider.ClientSet.CoreV1().Nodes().Get(context.TODO(), name, metav1.GetOptions{})
node.Kind = "Node"
node.APIVersion = "v1"
return node, err
}

func DeleteK8sNode(name string, contextId *string) error {
Expand Down
6 changes: 5 additions & 1 deletion kubernetes/orders.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ func GetOrder(namespaceName string, name string, contextId *string) (*v1.Order,
if err != nil {
return nil, err
}
return provider.ClientSet.AcmeV1().Orders(namespaceName).Get(context.TODO(), name, metav1.GetOptions{})
order, err := provider.ClientSet.AcmeV1().Orders(namespaceName).Get(context.TODO(), name, metav1.GetOptions{})
order.Kind = "Order"
order.APIVersion = "acme.cert-manager.io/v1"

return order, err
}

func UpdateK8sOrder(data v1.Order, contextId *string) utils.K8sWorkloadResult {
Expand Down
6 changes: 5 additions & 1 deletion kubernetes/persistent-volume-claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ func GetPersistentVolumeClaim(namespaceName string, name string, contextId *stri
if err != nil {
return nil, err
}
return provider.ClientSet.CoreV1().PersistentVolumeClaims(namespaceName).Get(context.TODO(), name, metav1.GetOptions{})
pvc, err := provider.ClientSet.CoreV1().PersistentVolumeClaims(namespaceName).Get(context.TODO(), name, metav1.GetOptions{})
pvc.Kind = "PersistentVolumeClaim"
pvc.APIVersion = "v1"

return pvc, err
}

func AllK8sPersistentVolumeClaims(namespaceName string, contextId *string) utils.K8sWorkloadResult {
Expand Down
6 changes: 5 additions & 1 deletion kubernetes/persistent-volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ func GetPersistentVolume(name string, contextId *string) (*core.PersistentVolume
if err != nil {
return nil, err
}
return provider.ClientSet.CoreV1().PersistentVolumes().Get(context.TODO(), name, metav1.GetOptions{})
pv, err := provider.ClientSet.CoreV1().PersistentVolumes().Get(context.TODO(), name, metav1.GetOptions{})
pv.Kind = "PersistentVolume"
pv.APIVersion = "v1"

return pv, err
}

func UpdateK8sPersistentVolume(data core.PersistentVolume, contextId *string) utils.K8sWorkloadResult {
Expand Down
Loading

0 comments on commit 3f0af5b

Please sign in to comment.