Skip to content

Commit

Permalink
delete repo
Browse files Browse the repository at this point in the history
  • Loading branch information
zreigz committed Dec 13, 2023
1 parent 3bb4465 commit 2996a72
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
1 change: 1 addition & 0 deletions controller/apis/deployments/v1alpha1/git_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type GitRepositoryStatus struct {
// CRD is then set to read-only mode and does not update Console API from CRD.
// +kubebuilder:validation:Optional
// +kubebuilder:validation:Type:=boolean
// +kubebuilder:default:=false
Existing *bool `json:"existing,omitempty"`
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ spec:
status:
properties:
existing:
default: false
description: Existing flag is set to true when Console API object
already exists when CRD is created. CRD is then set to read-only
mode and does not update Console API from CRD.
Expand Down
19 changes: 17 additions & 2 deletions controller/pkg/errors/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ func (k KnownError) String() string {
}

const (
ErrorNotFound KnownError = "could not find resource"
ErrExpected KnownError = "this is a transient, expected error"
ErrorNotFound KnownError = "could not find resource"
ErrExpected KnownError = "this is a transient, expected error"
ErrDeleteRepository = "could not delete repository"
)

type wrappedErrorResponse struct {
Expand Down Expand Up @@ -53,3 +54,17 @@ func IsNotFound(err error) bool {

return newAPIError(errorResponse).Has(ErrorNotFound)
}

func IsDeleteRepository(err error) bool {
if err == nil {
return false
}

errorResponse := new(client.ErrorResponse)
ok := errors.As(err, &errorResponse)
if !ok {
return false
}

return newAPIError(errorResponse).Has(ErrDeleteRepository)
}
4 changes: 3 additions & 1 deletion controller/pkg/gitrepository_controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,11 @@ func (r *Reconciler) handleDelete(ctx context.Context, repo *v1alpha1.GitReposit
}
if existingRepos != nil {
if err := r.ConsoleClient.DeleteRepository(*repo.Status.Id); err != nil {
if !errors.IsNotFound(err) {
if !errors.IsDeleteRepository(err) {
return ctrl.Result{}, err
}
logger.Info("waiting for the services")
return requeue, nil
}
}
if err := utils.TryRemoveFinalizer(ctx, r.Client, repo, RepoFinalizer); err != nil {
Expand Down
10 changes: 9 additions & 1 deletion controller/pkg/service_controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
if err := r.Get(ctx, client.ObjectKey{Name: service.Spec.RepositoryRef.Name, Namespace: service.Spec.RepositoryRef.Namespace}, repository); err != nil {
return ctrl.Result{}, err
}
if !repository.DeletionTimestamp.IsZero() {
log.Info("deleting service after repository deletion")
if err := r.Delete(ctx, service); err != nil {
return ctrl.Result{}, err
}
return requeue, nil
}

if repository.Status.Id == nil {
log.Info("Repository is not ready")
return requeue, nil
Expand Down Expand Up @@ -101,7 +109,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
return ctrl.Result{}, err
}
sort.Slice(attr.Configuration, func(i, j int) bool {
return attr.Configuration[i].Name < attr.Configuration[i].Name
return attr.Configuration[i].Name < attr.Configuration[j].Name
})
updater := console.ServiceUpdateAttributes{
Version: attr.Version,
Expand Down

0 comments on commit 2996a72

Please sign in to comment.