ProvisionedDashboard: Fix backend fails to delete dashboard due to missing branch and file

pull/106670/head
Yunwen Zheng 1 month ago
parent 5135d5c87d
commit 0cc1f14680
No known key found for this signature in database
  1. 9
      pkg/registry/apis/provisioning/repository/github.go
  2. 7
      pkg/registry/apis/provisioning/resources/dualwriter.go

@ -45,6 +45,7 @@ type GithubRepository interface {
Owner() string
Repo() string
Client() pgh.Client
EnsureBranchExists(ctx context.Context, branchName string) error
}
func NewGitHub(
@ -279,7 +280,7 @@ func (r *githubRepository) Create(ctx context.Context, path, ref string, data []
}
ctx, _ = r.logger(ctx, ref)
if err := r.ensureBranchExists(ctx, ref); err != nil {
if err := r.EnsureBranchExists(ctx, ref); err != nil {
return err
}
@ -314,7 +315,7 @@ func (r *githubRepository) Update(ctx context.Context, path, ref string, data []
}
ctx, _ = r.logger(ctx, ref)
if err := r.ensureBranchExists(ctx, ref); err != nil {
if err := r.EnsureBranchExists(ctx, ref); err != nil {
return err
}
@ -365,7 +366,7 @@ func (r *githubRepository) Delete(ctx context.Context, path, ref, comment string
}
ctx, _ = r.logger(ctx, ref)
if err := r.ensureBranchExists(ctx, ref); err != nil {
if err := r.EnsureBranchExists(ctx, ref); err != nil {
return err
}
@ -482,7 +483,7 @@ func isValidGitBranchName(branch string) bool {
return true
}
func (r *githubRepository) ensureBranchExists(ctx context.Context, branchName string) error {
func (r *githubRepository) EnsureBranchExists(ctx context.Context, branchName string) error {
if !isValidGitBranchName(branchName) {
return &apierrors.StatusError{
ErrStatus: metav1.Status{

@ -81,6 +81,13 @@ func (r *DualReadWriter) Delete(ctx context.Context, opts DualWriteOptions) (*Pa
return nil, fmt.Errorf("folder delete not supported")
}
// First ensure the branch exists if we're using a GitHub repository
if githubRepo, ok := r.repo.(repository.GithubRepository); ok && opts.Ref != "" {
if err := githubRepo.EnsureBranchExists(ctx, opts.Ref); err != nil {
return nil, fmt.Errorf("ensure branch exists: %w", err)
}
}
file, err := r.repo.Read(ctx, opts.Path, opts.Ref)
if err != nil {
return nil, fmt.Errorf("read file: %w", err)

Loading…
Cancel
Save