Skip to content

Commit

Permalink
Return correct deletion status from delete domain job
Browse files Browse the repository at this point in the history
Issue: cloudfoundry#2608
Co-authored-by: Georgi Sabev <[email protected]>
  • Loading branch information
2 people authored and kieron-dev committed Jul 12, 2023
1 parent acfc537 commit fd94c44
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 6 deletions.
2 changes: 1 addition & 1 deletion api/handlers/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (h *Job) get(r *http.Request) (*routing.Response, error) {
switch job.Type {
case syncSpaceJobType:
jobResponse = presenter.ForManifestApplyJob(job, h.serverURL)
case DomainDeleteJobType, RoleDeleteJobType:
case RoleDeleteJobType:
jobResponse = presenter.ForJob(job, []presenter.JobResponseError{}, presenter.StateComplete, h.serverURL)
default:
repository, ok := h.repositories[job.Type]
Expand Down
1 change: 0 additions & 1 deletion api/handlers/job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ var _ = Describe("Job", func() {

Expect(rr).To(HaveHTTPBody(SatisfyAll(bodyMatchers...)))
},
Entry("domain delete", "domain.delete", "cf-domain-guid"),
Entry("role delete", "role.delete", "cf-role-guid"),
Entry("apply manifest", "space.apply_manifest", "cf-space-guid"),
)
Expand Down
9 changes: 5 additions & 4 deletions api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,11 @@ func main() {
handlers.NewJob(
*serverURL,
map[string]handlers.DeletionRepository{
handlers.OrgDeleteJobType: orgRepo,
handlers.SpaceDeleteJobType: spaceRepo,
handlers.AppDeleteJobType: appRepo,
handlers.RouteDeleteJobType: routeRepo,
handlers.OrgDeleteJobType: orgRepo,
handlers.SpaceDeleteJobType: spaceRepo,
handlers.AppDeleteJobType: appRepo,
handlers.RouteDeleteJobType: routeRepo,
handlers.DomainDeleteJobType: domainRepo,
},
500*time.Millisecond,
),
Expand Down
7 changes: 7 additions & 0 deletions api/repositories/domain_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type DomainRecord struct {
Namespace string
CreatedAt time.Time
UpdatedAt *time.Time
DeletedAt *time.Time
}

type CreateDomainMessage struct {
Expand Down Expand Up @@ -198,6 +199,11 @@ func (r *DomainRepo) DeleteDomain(ctx context.Context, authInfo authorization.In
return nil
}

func (r *DomainRepo) GetDeletedAt(ctx context.Context, authInfo authorization.Info, domainGUID string) (*time.Time, error) {
domain, err := r.GetDomain(ctx, authInfo, domainGUID)
return domain.DeletedAt, err
}

func returnDomainList(domainList []korifiv1alpha1.CFDomain) []DomainRecord {
domainRecords := make([]DomainRecord, 0, len(domainList))

Expand All @@ -214,6 +220,7 @@ func cfDomainToDomainRecord(cfDomain *korifiv1alpha1.CFDomain) DomainRecord {
Namespace: cfDomain.Namespace,
CreatedAt: cfDomain.CreationTimestamp.Time,
UpdatedAt: getLastUpdatedTime(cfDomain),
DeletedAt: golangTime(cfDomain.DeletionTimestamp),
Labels: cfDomain.Labels,
Annotations: cfDomain.Annotations,
}
Expand Down
41 changes: 41 additions & 0 deletions api/repositories/domain_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,4 +376,45 @@ var _ = Describe("DomainRepository", func() {
})
})
})

Describe("GetDeletedAt", func() {
var (
deletionTime *time.Time
getErr error
)

JustBeforeEach(func() {
deletionTime, getErr = domainRepo.GetDeletedAt(ctx, authInfo, cfDomain.Name)
})

It("returns nil", func() {
Expect(getErr).NotTo(HaveOccurred())
Expect(deletionTime).To(BeNil())
})

When("the domain is being deleted", func() {
BeforeEach(func() {
Expect(k8s.PatchResource(ctx, k8sClient, cfDomain, func() {
cfDomain.Finalizers = append(cfDomain.Finalizers, "foo")
})).To(Succeed())

Expect(k8sClient.Delete(ctx, cfDomain)).To(Succeed())
})

It("returns the deletion time", func() {
Expect(getErr).NotTo(HaveOccurred())
Expect(deletionTime).To(PointTo(BeTemporally("~", time.Now(), time.Minute)))
})
})

When("the domain isn't found", func() {
BeforeEach(func() {
Expect(k8sClient.Delete(ctx, cfDomain)).To(Succeed())
})

It("errors", func() {
Expect(getErr).To(matchers.WrapErrorAssignableToTypeOf(apierrors.NotFoundError{}))
})
})
})
})
4 changes: 4 additions & 0 deletions tests/e2e/domains_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ var _ = Describe("Domain", func() {
g.Expect(err).NotTo(HaveOccurred())
g.Expect(string(resp.Body())).To(ContainSubstring("COMPLETE"))
}).Should(Succeed())

getDomainResp, err := certClient.R().Get("/v3/domains/" + domainGUID)
Expect(err).NotTo(HaveOccurred())
Expect(getDomainResp).To(HaveRestyStatusCode(http.StatusNotFound))
})

When("the domain has routes", func() {
Expand Down

0 comments on commit fd94c44

Please sign in to comment.