From a5c5f4feb9359018bda94cca7b9ec61b0c595287 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=88=E8=BD=A9?= Date: Thu, 30 Nov 2023 13:33:01 +0800 Subject: [PATCH] fix(region): skip sync meta if no public cloud register (#18827) --- pkg/compute/models/cloudimages.go | 4 ++++ pkg/compute/models/dbinstance_skus.go | 3 +++ pkg/compute/models/elasticcache_skus.go | 5 ++++- pkg/compute/models/nas_skus.go | 4 ++++ pkg/compute/models/nat_skus.go | 3 +++ pkg/compute/models/server_skus.go | 5 ++++- pkg/compute/models/waf_rule_groups.go | 4 ++++ 7 files changed, 26 insertions(+), 2 deletions(-) diff --git a/pkg/compute/models/cloudimages.go b/pkg/compute/models/cloudimages.go index db30fcdddb0..50cee1d2119 100644 --- a/pkg/compute/models/cloudimages.go +++ b/pkg/compute/models/cloudimages.go @@ -72,6 +72,10 @@ func SyncPublicCloudImages(ctx context.Context, userCred mcclient.TokenCredentia return } + if len(regions) == 0 { + return + } + meta, err := yunionmeta.FetchYunionmeta(ctx) if err != nil { log.Errorf("FetchYunionmeta %v", err) diff --git a/pkg/compute/models/dbinstance_skus.go b/pkg/compute/models/dbinstance_skus.go index cd4cf18ed54..0e3a4a14288 100644 --- a/pkg/compute/models/dbinstance_skus.go +++ b/pkg/compute/models/dbinstance_skus.go @@ -651,6 +651,9 @@ func SyncRegionDBInstanceSkus(ctx context.Context, userCred mcclient.TokenCreden log.Errorf("failed to fetch cloudregions: %v", err) return } + if len(cloudregions) == 0 { + return + } meta, err := yunionmeta.FetchYunionmeta(ctx) if err != nil { diff --git a/pkg/compute/models/elasticcache_skus.go b/pkg/compute/models/elasticcache_skus.go index cebd3217a08..cae58d05ca7 100644 --- a/pkg/compute/models/elasticcache_skus.go +++ b/pkg/compute/models/elasticcache_skus.go @@ -806,6 +806,10 @@ func SyncElasticCacheSkus(ctx context.Context, userCred mcclient.TokenCredential return } } + cloudregions := fetchSkuSyncCloudregions() + if len(cloudregions) == 0 { + return + } meta, err := yunionmeta.FetchYunionmeta(ctx) if err != nil { @@ -819,7 +823,6 @@ func SyncElasticCacheSkus(ctx context.Context, userCred mcclient.TokenCredential return } - cloudregions := fetchSkuSyncCloudregions() for i := range cloudregions { region := &cloudregions[i] diff --git a/pkg/compute/models/nas_skus.go b/pkg/compute/models/nas_skus.go index 0ea87f14374..27603fc2697 100644 --- a/pkg/compute/models/nas_skus.go +++ b/pkg/compute/models/nas_skus.go @@ -347,6 +347,10 @@ func SyncRegionNasSkus(ctx context.Context, userCred mcclient.TokenCredential, r return errors.Wrapf(err, "db.FetchModelObjects") } + if len(regions) == 0 { + return nil + } + meta, err := yunionmeta.FetchYunionmeta(ctx) if err != nil { return errors.Wrapf(err, "FetchYunionmeta") diff --git a/pkg/compute/models/nat_skus.go b/pkg/compute/models/nat_skus.go index 9997463f001..ffde8fa9a67 100644 --- a/pkg/compute/models/nat_skus.go +++ b/pkg/compute/models/nat_skus.go @@ -350,6 +350,9 @@ func SyncRegionNatSkus(ctx context.Context, userCred mcclient.TokenCredential, r if err != nil { return errors.Wrapf(err, "db.FetchModelObjects") } + if len(regions) == 0 { + return nil + } meta, err := yunionmeta.FetchYunionmeta(ctx) if err != nil { diff --git a/pkg/compute/models/server_skus.go b/pkg/compute/models/server_skus.go index 656674f8d62..61f790d0ecb 100644 --- a/pkg/compute/models/server_skus.go +++ b/pkg/compute/models/server_skus.go @@ -1600,6 +1600,10 @@ func SyncServerSkus(ctx context.Context, userCred mcclient.TokenCredential, isSt return } } + cloudregions := fetchSkuSyncCloudregions() + if len(cloudregions) == 0 { + return + } meta, err := yunionmeta.FetchYunionmeta(ctx) if err != nil { @@ -1613,7 +1617,6 @@ func SyncServerSkus(ctx context.Context, userCred mcclient.TokenCredential, isSt return } - cloudregions := fetchSkuSyncCloudregions() for i := range cloudregions { region := &cloudregions[i] diff --git a/pkg/compute/models/waf_rule_groups.go b/pkg/compute/models/waf_rule_groups.go index efe11eca383..9d411af6b1f 100644 --- a/pkg/compute/models/waf_rule_groups.go +++ b/pkg/compute/models/waf_rule_groups.go @@ -308,6 +308,10 @@ func SyncWafGroups(ctx context.Context, userCred mcclient.TokenCredential, isSta return errors.Wrapf(err, "fetchCloudEnvs") } + if len(cloudEnvs) == 0 { + return nil + } + meta, err := yunionmeta.FetchYunionmeta(ctx) if err != nil { return errors.Wrapf(err, "FetchYunionmeta")