Skip to content

Conversation

hasbro17
Copy link
Contributor

No description provided.

@hasbro17
Copy link
Contributor Author

Test cases:

func main() {
	samplePod := getSamplePod("Pod", "v1", "test-pod", "default")
	fmt.Printf("Pod template: \n%s\n\n", getFormattedJSON(samplePod))

	// Update non-existent pod
	logrus.Infof("Test case 1: Delete a non-existent pod")
	pod := samplePod
	// Create pod
	err := action.Delete(pod)
	if err != nil {
		logrus.Error(err)
	} else {
		logrus.Errorf("Deleted a non-existent pod")
		fmt.Printf("Deleted Pod: \n%s\n\n", getFormattedJSON(pod))
	}

	// Delete existing pod
	logrus.Infof("Test case 2: Delete an existing pod")
	pod = samplePod
	err = action.Create(pod)
	if err != nil {
		logrus.Errorf("Failed to create pod")
		logrus.Fatal(err)
	} else {
		fmt.Printf("Created Pod: \n%s\n\n", getFormattedJSON(pod))
	}
	// Wait until pod is created and running
	time.Sleep(time.Second * 10)
	// Delete the pod with grace period 5s
	metaDeleteOptions := &metav1.DeleteOptions{
		GracePeriodSeconds: func(t int64) *int64 { return &t }(5),
	}
	err = action.Delete(pod, action.WithDeleteOptions(metaDeleteOptions))
	if err != nil {
		logrus.Errorf("Failed to delete pod")
		logrus.Fatal(err)
	}
	logrus.Errorf("Successfully deleted pod")
}

Test Logs:

time="2018-03-26T23:12:36Z" level=info msg="Test case 1: Delete a non-existent pod"
time="2018-03-26T23:12:36Z" level=error msg="pods \"test-pod\" not found"
time="2018-03-26T23:12:36Z" level=info msg="Test case 2: Delete an existing pod"
Created Pod:
{
    "kind": "Pod",
    "apiVersion": "v1",
    "metadata": {
        "name": "test-pod",
        "namespace": "default",
        "selfLink": "/api/v1/namespaces/default/pods/test-pod",
        "uid": "2c395252-314b-11e8-ba9f-0800274106a1",
        "resourceVersion": "192861",
        "creationTimestamp": "2018-03-26T23:12:36Z"
    },
    ...
}

time="2018-03-26T23:12:46Z" level=error msg="Successfully deleted pod"

Delete pod has the correct grace period set:

$ kubectl get pod test-pod -o yaml
apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: 2018-03-26T23:12:36Z
  deletionGracePeriodSeconds: 5
  deletionTimestamp: 2018-03-26T23:12:51Z
  name: test-pod
  namespace: default
  resourceVersion: "192884"
...

@hasbro17 hasbro17 changed the title [WIP] action: add delete action: add delete Mar 26, 2018
@hasbro17
Copy link
Contributor Author

@fanminshi PTAL.

// Delete deletes the specified object
// Returns an error if the object’s TypeMeta(Kind, APIVersion) or ObjectMeta(Name, Namespace) is missing or incorrect.
// e.g NotFound https://github.com/kubernetes/apimachinery/blob/master/pkg/api/errors/errors.go#L418
// “opts” configures the k8s.io/apimachinery/pkg/apis/meta/v1.DeleteOptions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

“opts” configures the k8s.io/apimachinery/pkg/apis/meta/v1.DeleteOptions seems too specific. Also to configure v1.DeleteOptions is just one possible of DeleteOptions; Hence, i'd suggest to make it more generic.

Alternatively, if you want to be specific on what options are there, you can follow the KV comments from etcd:

	// When passed WithRange(end), Get will return the keys in the range [key, end).
	// When passed WithFromKey(), Get returns keys greater than or equal to key.
	// When passed WithRev(rev) with rev > 0, Get retrieves keys at the given revision;
	// if the required revision is compacted, the request will fail with ErrCompacted .
	// When passed WithLimit(limit), the number of returned keys is bounded by limit.
	// When passed WithSort(), the keys will be sorted.

https://github.com/coreos/etcd/blob/master/clientv3/kv.go#L42-L47

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, let me add the etcd style when passed ... comment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'll probably need to do that for Get and List operations

@fanminshi
Copy link
Contributor

Test cases to consider:

  • Delete an non-existant pod.
  • Delete without option.

@hasbro17
Copy link
Contributor Author

Test cases to consider:
Delete an non-existant pod.

Already tested that case in the above example.

Delete without option.

Tested that as well and works fine.

@fanminshi
Copy link
Contributor

You are right. hmm, not sure how I missed those two cases from your testing output.

@fanminshi
Copy link
Contributor

lgtm

@hasbro17 hasbro17 merged commit 2461007 into operator-framework:master Mar 26, 2018
@hasbro17 hasbro17 deleted the haseeb/add-action-delete branch March 26, 2018 23:50
m1kola pushed a commit to m1kola/operator-sdk that referenced this pull request Jun 7, 2024
…ating-.ci-operator.yaml-`build_root_image`-from-openshift/release

Updating .ci-operator.yaml `build_root_image` from openshift/release
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants