77 "errors"
88 "os"
99 "os/exec"
10+ "sync"
1011
1112 "go.uber.org/zap"
1213 networkingv1 "k8s.io/api/networking/v1"
@@ -41,6 +42,7 @@ type adcClient struct {
4142 Token string
4243 GatewayGroup string
4344 configs map [ResourceKind ][]adcConfig
45+ sync.Mutex
4446}
4547
4648type Task struct {
@@ -61,10 +63,6 @@ func New() (provider.Provider, error) {
6163 }, nil
6264}
6365
64- func (d * adcClient ) getConfigs (rk ResourceKind ) []adcConfig {
65- return d .configs [rk ]
66- }
67-
6866func (d * adcClient ) getConfigsForGatewayProxy (tctx * provider.TranslateContext , gatewayProxy * v1alpha1.GatewayProxy ) (* adcConfig , error ) {
6967 if gatewayProxy == nil || gatewayProxy .Spec .Provider == nil {
7068 return nil , nil
@@ -110,7 +108,22 @@ func (d *adcClient) getConfigsForGatewayProxy(tctx *provider.TranslateContext, g
110108 return & config , nil
111109}
112110
111+ func (d * adcClient ) deleteConfigs (rk ResourceKind ) {
112+ d .Lock ()
113+ defer d .Unlock ()
114+ delete (d .configs , rk )
115+ }
116+
117+ func (d * adcClient ) getConfigs (rk ResourceKind ) []adcConfig {
118+ d .Lock ()
119+ defer d .Unlock ()
120+ return d .configs [rk ]
121+ }
122+
113123func (d * adcClient ) updateConfigs (rk ResourceKind , tctx * provider.TranslateContext ) error {
124+ d .Lock ()
125+ defer d .Unlock ()
126+
114127 var configs []adcConfig
115128 for _ , gatewayProxy := range tctx .GatewayProxies {
116129 config , err := d .getConfigsForGatewayProxy (tctx , & gatewayProxy )
@@ -208,12 +221,18 @@ func (d *adcClient) Delete(ctx context.Context, obj client.Object) error {
208221
209222 configs := d .getConfigs (rk )
210223
211- return d .sync (Task {
224+ err := d .sync (Task {
212225 Name : obj .GetName (),
213226 Labels : labels ,
214227 ResourceTypes : resourceTypes ,
215228 configs : configs ,
216229 })
230+ if err != nil {
231+ return err
232+ }
233+
234+ d .deleteConfigs (rk )
235+ return nil
217236}
218237
219238func (d * adcClient ) sync (task Task ) error {
0 commit comments