Compare commits

...

1 Commits

Author SHA1 Message Date
aby913
0dac2c4991 bfl: fix delete custom domain url (#2218) 2025-12-11 21:07:01 +08:00
2 changed files with 32 additions and 3 deletions

View File

@@ -280,7 +280,7 @@ func (c *certManager) GetCustomDomainOnCloudflare(customDomain string) (*Respons
func (c *certManager) DeleteCustomDomainOnCloudflare(customDomain string) (*Response, error) {
payload := CustomDomainPayload{Name: string(c.terminusName), CustomDomain: customDomain}
var r Response
err := c.request(context.Background(), "DELETE", constants.APIDNSSetCloudFlareTunnel, payload, &r)
err := c.request(context.Background(), "DELETE", constants.APIDNSAddCustomDomain, payload, &r)
if err != nil && !strings.Contains(err.Error(), "The custom hostname was not found") {
return nil, err
}

View File

@@ -26,8 +26,10 @@ import (
kerrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/util/retry"
"k8s.io/klog/v2"
)
@@ -116,11 +118,32 @@ func (s *Subscriber) Do(ctx context.Context, obj interface{}, action watchers.Ac
return fmt.Errorf("%s, app: %s-%s", err.Error(), request.Spec.Name, request.Spec.Namespace)
}
case watchers.DELETE:
return s.removeCustomDomainCnameData(request)
return s.removeCustomDomainRetry(request)
}
return nil
}
func (s *Subscriber) removeCustomDomainRetry(request *appv1.Application) error {
backoff := wait.Backoff{
Duration: 2 * time.Second,
Factor: 2,
Jitter: 0.1,
Steps: 5,
}
var err = retry.OnError(backoff, func(err error) bool {
return true
}, func() error {
return s.removeCustomDomainCnameData(request)
})
if err != nil {
klog.Errorf("remove custom domain error: %v", err)
}
return nil
}
func (s *Subscriber) checkCustomDomainStatus(app *appv1.Application) error {
var err error
customDomains, ok := app.Spec.Settings[constants.ApplicationCustomDomain]
@@ -390,7 +413,13 @@ func (s *Subscriber) removeCustomDomainCnameData(app *appv1.Application) error {
if !ok || customDomainName == nil {
continue
}
_, err = cm.DeleteCustomDomainOnCloudflare(customDomainName.(string))
var domainName = customDomainName.(string)
if domainName == "" {
continue
}
_, err = cm.DeleteCustomDomainOnCloudflare(domainName)
if err != nil {
break
}