Commit ce4ae51e authored by Michelle Noorali's avatar Michelle Noorali Committed by GitHub

Merge pull request #1146 from michelleN/bug/1133-fix-delete

fix(kube): delete should skip resources not found
parents 60b41888 f062cff5
...@@ -215,23 +215,31 @@ func (c *Client) Update(namespace string, currentReader, targetReader io.Reader) ...@@ -215,23 +215,31 @@ func (c *Client) Update(namespace string, currentReader, targetReader io.Reader)
func (c *Client) Delete(namespace string, reader io.Reader) error { func (c *Client) Delete(namespace string, reader io.Reader) error {
return perform(c, namespace, reader, func(info *resource.Info) error { return perform(c, namespace, reader, func(info *resource.Info) error {
log.Printf("Starting delete for %s", info.Name) log.Printf("Starting delete for %s", info.Name)
reaper, err := c.Reaper(info.Mapping) reaper, err := c.Reaper(info.Mapping)
if err != nil { if err != nil {
// If there is no reaper for this resources, delete it. // If there is no reaper for this resources, delete it.
if kubectl.IsNoSuchReaperError(err) { if kubectl.IsNoSuchReaperError(err) {
return resource.NewHelper(info.Client, info.Mapping).Delete(info.Namespace, info.Name) err := resource.NewHelper(info.Client, info.Mapping).Delete(info.Namespace, info.Name)
return skipIfNotFound(err)
} }
return err return err
} }
log.Printf("Using reaper for deleting %s", info.Name) log.Printf("Using reaper for deleting %s", info.Name)
err = reaper.Stop(info.Namespace, info.Name, 0, nil) err = reaper.Stop(info.Namespace, info.Name, 0, nil)
return skipIfNotFound(err)
})
}
func skipIfNotFound(err error) error {
if err != nil && errors.IsNotFound(err) { if err != nil && errors.IsNotFound(err) {
log.Printf("%v", err) log.Printf("%v", err)
return nil return nil
} }
return err return err
})
} }
// WatchUntilReady watches the resource given in the reader, and waits until it is ready. // WatchUntilReady watches the resource given in the reader, and waits until it is ready.
......
...@@ -126,11 +126,48 @@ func TestReal(t *testing.T) { ...@@ -126,11 +126,48 @@ func TestReal(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
if err := New(nil).Delete("test", strings.NewReader(guestbookManifest)); err != nil { testSvcEndpointManifest := testServiceManifest + "\n---\n" + testEndpointManifest
c := New(nil)
if err := c.Create("test-delete", strings.NewReader(testSvcEndpointManifest)); err != nil {
t.Fatal(err)
}
if err := c.Delete("test-delete", strings.NewReader(testEndpointManifest)); err != nil {
t.Fatal(err)
}
// ensures that delete does not fail if a resource is not found
if err := c.Delete("test-delete", strings.NewReader(testSvcEndpointManifest)); err != nil {
t.Fatal(err) t.Fatal(err)
} }
} }
const testServiceManifest = `
kind: Service
apiVersion: v1
metadata:
name: my-service
spec:
selector:
app: myapp
ports:
- port: 80
protocol: TCP
targetPort: 9376
`
const testEndpointManifest = `
kind: Endpoints
apiVersion: v1
metadata:
name: my-service
subsets:
- addresses:
- ip: "1.2.3.4"
ports:
- port: 9376
`
const guestbookManifest = ` const guestbookManifest = `
apiVersion: v1 apiVersion: v1
kind: Service kind: Service
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment