Skip to content

Commit

Permalink
Update client-go to v0.25.12 (#275)
Browse files Browse the repository at this point in the history
* Update client-go to v0.25.12

Update client-go and related modules to v0.25.12
Update references to `batch/v1beta1` to `batch/v1` (K8s 1.25)

Signed-off-by: Todd Ekenstam <[email protected]>

* Add unit test for objects.go

Signed-off-by: Todd Ekenstam <[email protected]>

* More unit tests

Signed-off-by: Todd Ekenstam <[email protected]>

* Another CronJob unit test

Signed-off-by: Todd Ekenstam <[email protected]>

* Improvements to tests

Signed-off-by: Todd Ekenstam <[email protected]>

* Add more unit tests

Signed-off-by: Todd Ekenstam <[email protected]>

---------

Signed-off-by: Todd Ekenstam <[email protected]>
  • Loading branch information
tekenstam authored Sep 16, 2023
1 parent d1fd2aa commit 7baa75a
Show file tree
Hide file tree
Showing 11 changed files with 519 additions and 65 deletions.
3 changes: 1 addition & 2 deletions config/crd/bases/addonmgr.keikoproj.io_addons.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.9.2
creationTimestamp: null
controller-gen.kubebuilder.io/version: v0.12.0
name: addons.addonmgr.keikoproj.io
spec:
group: addonmgr.keikoproj.io
Expand Down
2 changes: 0 additions & 2 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
creationTimestamp: null
name: manager-role
rules:
- apiGroups:
Expand Down Expand Up @@ -102,7 +101,6 @@ rules:
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
creationTimestamp: null
name: manager-role
namespace: system
rules:
Expand Down
35 changes: 6 additions & 29 deletions controllers/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,20 @@ import (

appsv1 "k8s.io/api/apps/v1"
batchv1 "k8s.io/api/batch/v1"
batchv1beta1 "k8s.io/api/batch/v1beta1"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/labels"
)

func ObserveService(cli client.Client, namespace string, selector labels.Selector) ([]addonmgrv1alpha1.ObjectStatus, error) {
services := &v1.ServiceList{}
services := &corev1.ServiceList{}
err := cli.List(context.TODO(), services, &client.ListOptions{
LabelSelector: selector,
Namespace: namespace,
})
if err != nil {
return nil, fmt.Errorf("failed to list services %v", err)
}
if services == nil {
return nil, fmt.Errorf("services is empty")
}

res := []addonmgrv1alpha1.ObjectStatus{}
for _, service := range services.Items {
if service.ObjectMeta.Namespace == namespace {
Expand All @@ -50,9 +46,7 @@ func ObserveJob(cli client.Client, namespace string, selector labels.Selector) (
if err != nil {
return nil, fmt.Errorf("failed to list cronjobs %v", err)
}
if jobs == nil {
return nil, fmt.Errorf("batchv1.JobList is empty")
}

res := []addonmgrv1alpha1.ObjectStatus{}
for _, job := range jobs.Items {
res = append(res, addonmgrv1alpha1.ObjectStatus{
Expand All @@ -66,22 +60,20 @@ func ObserveJob(cli client.Client, namespace string, selector labels.Selector) (
}

func ObserveCronJob(cli client.Client, namespace string, selector labels.Selector) ([]addonmgrv1alpha1.ObjectStatus, error) {
cronJobs := &batchv1beta1.CronJobList{}
cronJobs := &batchv1.CronJobList{}
err := cli.List(context.TODO(), cronJobs, &client.ListOptions{
LabelSelector: selector,
Namespace: namespace,
})
if err != nil {
return nil, fmt.Errorf("failed to list cronjobs %v", err)
}
if cronJobs == nil {
return nil, fmt.Errorf("batchv1beta1.CronJobList is empty")
}

res := []addonmgrv1alpha1.ObjectStatus{}
for _, cronJob := range cronJobs.Items {
res = append(res, addonmgrv1alpha1.ObjectStatus{
Kind: "CronJob",
Group: "batch/v1beta1",
Group: "batch/v1",
Name: cronJob.GetName(),
Link: cronJob.GetSelfLink(),
})
Expand All @@ -96,9 +88,6 @@ func ObserveDeployment(cli client.Client, namespace string, selector labels.Sele
if err != nil {
return nil, err
}
if deployments == nil {
return nil, fmt.Errorf("failed to list deployments")
}

res := []addonmgrv1alpha1.ObjectStatus{}
for _, deployment := range deployments.Items {
Expand All @@ -119,9 +108,6 @@ func ObserveDaemonSet(cli client.Client, namespace string, selector labels.Selec
if err != nil {
return nil, err
}
if daemonSets == nil {
return nil, fmt.Errorf("failed to list daemonSets")
}

res := []addonmgrv1alpha1.ObjectStatus{}
for _, deployment := range daemonSets.Items {
Expand All @@ -142,9 +128,6 @@ func ObserveReplicaSet(cli client.Client, namespace string, selector labels.Sele
if err != nil {
return nil, err
}
if replicaSets == nil {
return nil, fmt.Errorf("failed to list replicaSets")
}

res := []addonmgrv1alpha1.ObjectStatus{}
for _, replicaSet := range replicaSets.Items {
Expand All @@ -165,9 +148,6 @@ func ObserveStatefulSet(cli client.Client, name string, selector labels.Selector
if err != nil {
return nil, err
}
if statefulSets == nil {
return nil, fmt.Errorf("failed to list replicaSets")
}

res := []addonmgrv1alpha1.ObjectStatus{}
for _, statefulSet := range statefulSets.Items {
Expand All @@ -188,9 +168,6 @@ func ObserveNamespace(cli client.Client, name string, selector labels.Selector)
if err != nil {
return nil, err
}
if namespaces == nil {
return nil, fmt.Errorf("failed to list namespace")
}

res := []addonmgrv1alpha1.ObjectStatus{}
for _, namespace := range namespaces.Items {
Expand Down
Loading

0 comments on commit 7baa75a

Please sign in to comment.