Skip to content

Commit ce01dfc

Browse files
committed
Cleanup unused test functions - cont-ed
Following up the work started in 0c0bd6d this is further cleaning up the test/utils directory getting rid of unused functions.
1 parent 89283e0 commit ce01dfc

File tree

7 files changed

+0
-392
lines changed

7 files changed

+0
-392
lines changed

test/utils/audit.go

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -128,55 +128,6 @@ func CheckAuditLinesFiltered(stream io.Reader, expected []AuditEvent, version sc
128128
return missingReport, nil
129129
}
130130

131-
// CheckAuditList searches an audit event list for the expected audit events.
132-
func CheckAuditList(el auditinternal.EventList, expected []AuditEvent) (missing []AuditEvent, err error) {
133-
expectations := newAuditEventTracker(expected)
134-
135-
for _, e := range el.Items {
136-
event, err := testEventFromInternal(&e)
137-
if err != nil {
138-
return expected, err
139-
}
140-
141-
expectations.Mark(event)
142-
}
143-
144-
return expectations.Missing(), nil
145-
}
146-
147-
// CheckForDuplicates checks a list for duplicate events
148-
func CheckForDuplicates(el auditinternal.EventList) (auditinternal.EventList, error) {
149-
// existingEvents holds a slice of audit events that have been seen
150-
existingEvents := []AuditEvent{}
151-
duplicates := auditinternal.EventList{}
152-
for _, e := range el.Items {
153-
event, err := testEventFromInternal(&e)
154-
if err != nil {
155-
return duplicates, err
156-
}
157-
event.ID = e.AuditID
158-
for _, existing := range existingEvents {
159-
if reflect.DeepEqual(existing, event) {
160-
duplicates.Items = append(duplicates.Items, e)
161-
continue
162-
}
163-
}
164-
existingEvents = append(existingEvents, event)
165-
}
166-
167-
var err error
168-
if len(duplicates.Items) > 0 {
169-
err = fmt.Errorf("failed duplicate check")
170-
}
171-
172-
return duplicates, err
173-
}
174-
175-
// testEventFromInternal takes an internal audit event and returns a test event
176-
func testEventFromInternal(e *auditinternal.Event) (AuditEvent, error) {
177-
return testEventFromInternalFiltered(e, nil)
178-
}
179-
180131
// testEventFromInternalFiltered takes an internal audit event and returns a test event, customAnnotationsFilter
181132
// controls which audit annotations are added to AuditEvent.CustomAuditAnnotations.
182133
// If the customAnnotationsFilter is nil, AuditEvent.CustomAuditAnnotations will be empty.

test/utils/conditions.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,3 @@ func TerminatedContainers(pod *v1.Pod) map[string]string {
103103
}
104104
return states
105105
}
106-
107-
// PodNotReady checks whether pod p's has a ready condition of status false.
108-
func PodNotReady(p *v1.Pod) (bool, error) {
109-
// Check the ready condition is false.
110-
if podutil.IsPodReady(p) {
111-
return false, fmt.Errorf("pod '%s' on '%s' didn't have condition {%v %v}; conditions: %v",
112-
p.ObjectMeta.Name, p.Spec.NodeName, v1.PodReady, v1.ConditionFalse, p.Status.Conditions)
113-
}
114-
return true, nil
115-
}

test/utils/create_resources.go

Lines changed: 0 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ import (
2424
"time"
2525

2626
apps "k8s.io/api/apps/v1"
27-
batch "k8s.io/api/batch/v1"
28-
storage "k8s.io/api/storage/v1"
29-
3027
v1 "k8s.io/api/core/v1"
3128
apierrors "k8s.io/apimachinery/pkg/api/errors"
3229
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -121,74 +118,6 @@ func CreateDeploymentWithRetries(c clientset.Interface, namespace string, obj *a
121118
return RetryWithExponentialBackOff(createFunc)
122119
}
123120

124-
func CreateDaemonSetWithRetries(c clientset.Interface, namespace string, obj *apps.DaemonSet) error {
125-
if obj == nil {
126-
return fmt.Errorf("object provided to create is empty")
127-
}
128-
createFunc := func() (bool, error) {
129-
_, err := c.AppsV1().DaemonSets(namespace).Create(context.TODO(), obj, metav1.CreateOptions{})
130-
if isGenerateNameConflict(obj.ObjectMeta, err) {
131-
return false, nil
132-
}
133-
if err == nil || apierrors.IsAlreadyExists(err) {
134-
return true, nil
135-
}
136-
return false, fmt.Errorf("failed to create object with non-retriable error: %v", err)
137-
}
138-
return RetryWithExponentialBackOff(createFunc)
139-
}
140-
141-
func CreateJobWithRetries(c clientset.Interface, namespace string, obj *batch.Job) error {
142-
if obj == nil {
143-
return fmt.Errorf("object provided to create is empty")
144-
}
145-
createFunc := func() (bool, error) {
146-
_, err := c.BatchV1().Jobs(namespace).Create(context.TODO(), obj, metav1.CreateOptions{})
147-
if isGenerateNameConflict(obj.ObjectMeta, err) {
148-
return false, nil
149-
}
150-
if err == nil || apierrors.IsAlreadyExists(err) {
151-
return true, nil
152-
}
153-
return false, fmt.Errorf("failed to create object with non-retriable error: %v", err)
154-
}
155-
return RetryWithExponentialBackOff(createFunc)
156-
}
157-
158-
func CreateSecretWithRetries(c clientset.Interface, namespace string, obj *v1.Secret) error {
159-
if obj == nil {
160-
return fmt.Errorf("object provided to create is empty")
161-
}
162-
createFunc := func() (bool, error) {
163-
_, err := c.CoreV1().Secrets(namespace).Create(context.TODO(), obj, metav1.CreateOptions{})
164-
if isGenerateNameConflict(obj.ObjectMeta, err) {
165-
return false, nil
166-
}
167-
if err == nil || apierrors.IsAlreadyExists(err) {
168-
return true, nil
169-
}
170-
return false, fmt.Errorf("failed to create object with non-retriable error: %v", err)
171-
}
172-
return RetryWithExponentialBackOff(createFunc)
173-
}
174-
175-
func CreateConfigMapWithRetries(c clientset.Interface, namespace string, obj *v1.ConfigMap) error {
176-
if obj == nil {
177-
return fmt.Errorf("object provided to create is empty")
178-
}
179-
createFunc := func() (bool, error) {
180-
_, err := c.CoreV1().ConfigMaps(namespace).Create(context.TODO(), obj, metav1.CreateOptions{})
181-
if isGenerateNameConflict(obj.ObjectMeta, err) {
182-
return false, nil
183-
}
184-
if err == nil || apierrors.IsAlreadyExists(err) {
185-
return true, nil
186-
}
187-
return false, fmt.Errorf("failed to create object with non-retriable error: %v", err)
188-
}
189-
return RetryWithExponentialBackOff(createFunc)
190-
}
191-
192121
func CreateServiceWithRetries(c clientset.Interface, namespace string, obj *v1.Service) error {
193122
if obj == nil {
194123
return fmt.Errorf("object provided to create is empty")
@@ -206,40 +135,6 @@ func CreateServiceWithRetries(c clientset.Interface, namespace string, obj *v1.S
206135
return RetryWithExponentialBackOff(createFunc)
207136
}
208137

209-
func CreateStorageClassWithRetries(c clientset.Interface, obj *storage.StorageClass) error {
210-
if obj == nil {
211-
return fmt.Errorf("object provided to create is empty")
212-
}
213-
createFunc := func() (bool, error) {
214-
_, err := c.StorageV1().StorageClasses().Create(context.TODO(), obj, metav1.CreateOptions{})
215-
if isGenerateNameConflict(obj.ObjectMeta, err) {
216-
return false, nil
217-
}
218-
if err == nil || apierrors.IsAlreadyExists(err) {
219-
return true, nil
220-
}
221-
return false, fmt.Errorf("failed to create object with non-retriable error: %v", err)
222-
}
223-
return RetryWithExponentialBackOff(createFunc)
224-
}
225-
226-
func CreateResourceQuotaWithRetries(c clientset.Interface, namespace string, obj *v1.ResourceQuota) error {
227-
if obj == nil {
228-
return fmt.Errorf("object provided to create is empty")
229-
}
230-
createFunc := func() (bool, error) {
231-
_, err := c.CoreV1().ResourceQuotas(namespace).Create(context.TODO(), obj, metav1.CreateOptions{})
232-
if isGenerateNameConflict(obj.ObjectMeta, err) {
233-
return false, nil
234-
}
235-
if err == nil || apierrors.IsAlreadyExists(err) {
236-
return true, nil
237-
}
238-
return false, fmt.Errorf("failed to create object with non-retriable error: %v", err)
239-
}
240-
return RetryWithExponentialBackOff(createFunc)
241-
}
242-
243138
func CreatePersistentVolumeWithRetries(c clientset.Interface, obj *v1.PersistentVolume) error {
244139
if obj == nil {
245140
return fmt.Errorf("object provided to create is empty")

test/utils/delete_resources.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"context"
2323
"fmt"
2424

25-
apierrors "k8s.io/apimachinery/pkg/api/errors"
2625
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2726
"k8s.io/apimachinery/pkg/runtime/schema"
2827
clientset "k8s.io/client-go/kubernetes"
@@ -56,14 +55,3 @@ func DeleteResource(c clientset.Interface, kind schema.GroupKind, namespace, nam
5655
return fmt.Errorf("unsupported kind when deleting: %v", kind)
5756
}
5857
}
59-
60-
func DeleteResourceWithRetries(c clientset.Interface, kind schema.GroupKind, namespace, name string, options metav1.DeleteOptions) error {
61-
deleteFunc := func() (bool, error) {
62-
err := DeleteResource(c, kind, namespace, name, options)
63-
if err == nil || apierrors.IsNotFound(err) {
64-
return true, nil
65-
}
66-
return false, fmt.Errorf("failed to delete object with non-retriable error: %v", err)
67-
}
68-
return RetryWithExponentialBackOff(deleteFunc)
69-
}

test/utils/deployment.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -328,25 +328,6 @@ func WaitForObservedDeployment(c clientset.Interface, ns, deploymentName string,
328328
}, desiredGeneration, 2*time.Second, 1*time.Minute)
329329
}
330330

331-
// WaitForDeploymentRollbackCleared waits for given deployment either started rolling back or doesn't need to rollback.
332-
func WaitForDeploymentRollbackCleared(c clientset.Interface, ns, deploymentName string, pollInterval, pollTimeout time.Duration) error {
333-
err := wait.PollImmediate(pollInterval, pollTimeout, func() (bool, error) {
334-
deployment, err := c.AppsV1().Deployments(ns).Get(context.TODO(), deploymentName, metav1.GetOptions{})
335-
if err != nil {
336-
return false, err
337-
}
338-
// Rollback not set or is kicked off
339-
if deployment.Annotations[apps.DeprecatedRollbackTo] == "" {
340-
return true, nil
341-
}
342-
return false, nil
343-
})
344-
if err != nil {
345-
return fmt.Errorf("error waiting for deployment %s rollbackTo to be cleared: %v", deploymentName, err)
346-
}
347-
return nil
348-
}
349-
350331
// WaitForDeploymentUpdatedReplicasGTE waits for given deployment to be observed by the controller and has at least a number of updatedReplicas
351332
func WaitForDeploymentUpdatedReplicasGTE(c clientset.Interface, ns, deploymentName string, minUpdatedReplicas int32, desiredGeneration int64, pollInterval, pollTimeout time.Duration) error {
352333
var deployment *apps.Deployment

test/utils/replicaset.go

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -67,26 +67,3 @@ func WaitRSStable(t *testing.T, clientSet clientset.Interface, rs *apps.ReplicaS
6767
}
6868
return nil
6969
}
70-
71-
func UpdateReplicaSetStatusWithRetries(c clientset.Interface, namespace, name string, applyUpdate UpdateReplicaSetFunc, logf LogfFn, pollInterval, pollTimeout time.Duration) (*apps.ReplicaSet, error) {
72-
var rs *apps.ReplicaSet
73-
var updateErr error
74-
pollErr := wait.PollImmediate(pollInterval, pollTimeout, func() (bool, error) {
75-
var err error
76-
if rs, err = c.AppsV1().ReplicaSets(namespace).Get(context.TODO(), name, metav1.GetOptions{}); err != nil {
77-
return false, err
78-
}
79-
// Apply the update, then attempt to push it to the apiserver.
80-
applyUpdate(rs)
81-
if rs, err = c.AppsV1().ReplicaSets(namespace).UpdateStatus(context.TODO(), rs, metav1.UpdateOptions{}); err == nil {
82-
logf("Updating replica set %q", name)
83-
return true, nil
84-
}
85-
updateErr = err
86-
return false, nil
87-
})
88-
if wait.Interrupted(pollErr) {
89-
pollErr = fmt.Errorf("couldn't apply the provided update to replicaset %q: %v", name, updateErr)
90-
}
91-
return rs, pollErr
92-
}

0 commit comments

Comments
 (0)