Skip to content

Commit bd40420

Browse files
committed
fix: resolve CI failures - format and linting issues
Fix all issues causing CI to fail: 1. Go format issues (go fmt): - pkg/console/service/rule_version.go - pkg/core/resource/apis/mesh/v1alpha1/rule_intent_types.go - pkg/core/versioning/resource_store_adapter.go - pkg/core/versioning/subscriber.go - pkg/store/dbcommon/gorm_store.go 2. Go vet issues - mutex copy in DeepCopy: - Use proto.Clone() instead of direct struct copy - Fixes mutex copy warnings for RuleVersion/RuleIntent/RuleMeta - Added google.golang.org/protobuf/proto import 3. Test compilation errors: - Fix ListResources() → List() in store tests - Add type assertions for model.Resource - Remove unused imports (testing, require, memorystore) All changes ensure: - go fmt ./... passes - go vet ./... passes - go build ./... passes - Tests compile successfully Related: #1477 CI failure fix
1 parent 6851202 commit bd40420

9 files changed

Lines changed: 71 additions & 80 deletions

File tree

pkg/console/service/rule_version.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@ func ListRuleVersions(ctx consolectx.Context, kindName RuleKindName) (*versionin
131131
meshresource.RuleVersionKind,
132132
[]index.IndexCondition{
133133
{
134-
IndexName: index.ByParentRuleIndexName,
135-
Value: fmt.Sprintf("%s/%s/%s", kindName.Kind, kindName.Mesh, kindName.Name),
136-
},
134+
IndexName: index.ByParentRuleIndexName,
135+
Value: fmt.Sprintf("%s/%s/%s", kindName.Kind, kindName.Mesh, kindName.Name),
136+
},
137137
},
138138
)
139139
if err != nil {
@@ -177,9 +177,9 @@ func GetRuleVersion(ctx consolectx.Context, kindName RuleKindName, versionID int
177177
meshresource.RuleVersionKind,
178178
[]index.IndexCondition{
179179
{
180-
IndexName: index.ByParentRuleIndexName,
181-
Value: fmt.Sprintf("%s/%s/%s", kindName.Kind, kindName.Mesh, kindName.Name),
182-
},
180+
IndexName: index.ByParentRuleIndexName,
181+
Value: fmt.Sprintf("%s/%s/%s", kindName.Kind, kindName.Mesh, kindName.Name),
182+
},
183183
},
184184
)
185185
if err != nil {
@@ -311,9 +311,9 @@ func isCurrentVersion(rm manager.ResourceManager, kindName RuleKindName, version
311311
meshresource.RuleVersionKind,
312312
[]index.IndexCondition{
313313
{
314-
IndexName: index.ByParentRuleIndexName,
315-
Value: fmt.Sprintf("%s/%s/%s", kindName.Kind, kindName.Mesh, kindName.Name),
316-
},
314+
IndexName: index.ByParentRuleIndexName,
315+
Value: fmt.Sprintf("%s/%s/%s", kindName.Kind, kindName.Mesh, kindName.Name),
316+
},
317317
},
318318
)
319319
if err != nil {

pkg/core/manager/manager_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,13 @@
1818
package manager
1919

2020
import (
21-
"testing"
22-
23-
"github.com/stretchr/testify/require"
2421
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2522
"k8s.io/apimachinery/pkg/runtime"
2623
"k8s.io/apimachinery/pkg/runtime/schema"
2724

2825
"github.com/apache/dubbo-admin/pkg/core/governor"
2926
"github.com/apache/dubbo-admin/pkg/core/resource/model"
3027
corestore "github.com/apache/dubbo-admin/pkg/core/store"
31-
memorystore "github.com/apache/dubbo-admin/pkg/store/memory"
3228
)
3329

3430
type managerTestResource struct {

pkg/core/resource/apis/mesh/v1alpha1/rule_intent_types.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,20 @@ package v1alpha1
1919

2020
import (
2121
"encoding/json"
22-
k8sruntime "k8s.io/apimachinery/pkg/runtime"
2322
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23+
k8sruntime "k8s.io/apimachinery/pkg/runtime"
2424

2525
meshproto "github.com/apache/dubbo-admin/api/mesh/v1alpha1"
2626
"github.com/apache/dubbo-admin/pkg/core/resource/model"
27+
"google.golang.org/protobuf/proto"
2728
)
2829

2930
// RuleIntentResource represents a pending mutation to a rule
3031
type RuleIntentResource struct {
3132
metav1.TypeMeta `json:",inline"`
3233
metav1.ObjectMeta `json:"metadata,omitempty"`
33-
Mesh string `json:"mesh,omitempty"`
34-
Spec *meshproto.RuleIntent `json:"spec,omitempty"`
34+
Mesh string `json:"mesh,omitempty"`
35+
Spec *meshproto.RuleIntent `json:"spec,omitempty"`
3536
}
3637

3738
func (r *RuleIntentResource) ResourceKind() model.ResourceKind {
@@ -69,8 +70,7 @@ func (r *RuleIntentResource) DeepCopyObject() k8sruntime.Object {
6970
Mesh: r.Mesh,
7071
}
7172
if r.Spec != nil {
72-
out.Spec = &meshproto.RuleIntent{}
73-
*out.Spec = *r.Spec
73+
out.Spec = proto.Clone(r.Spec).(*meshproto.RuleIntent)
7474
}
7575
return out
7676
}
@@ -148,8 +148,7 @@ func (r *RuleMetaResource) DeepCopyObject() k8sruntime.Object {
148148
Mesh: r.Mesh,
149149
}
150150
if r.Spec != nil {
151-
out.Spec = &meshproto.RuleMeta{}
152-
*out.Spec = *r.Spec
151+
out.Spec = proto.Clone(r.Spec).(*meshproto.RuleMeta)
153152
}
154153
return out
155154
}

pkg/core/resource/apis/mesh/v1alpha1/rule_version_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
meshproto "github.com/apache/dubbo-admin/api/mesh/v1alpha1"
2727
"github.com/apache/dubbo-admin/pkg/core/logger"
2828
coremodel "github.com/apache/dubbo-admin/pkg/core/resource/model"
29+
"google.golang.org/protobuf/proto"
2930
)
3031

3132
const (
@@ -84,8 +85,7 @@ func (r *RuleVersionResource) DeepCopyObject() k8sruntime.Object {
8485
Mesh: r.Mesh,
8586
}
8687
if r.Spec != nil {
87-
out.Spec = &meshproto.RuleVersion{}
88-
*out.Spec = *r.Spec
88+
out.Spec = proto.Clone(r.Spec).(*meshproto.RuleVersion)
8989
}
9090
return out
9191
}

pkg/core/versioning/resource_store_adapter.go

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,18 @@ func (a *ResourceStoreAdapter) InsertVersion(req InsertRequest, maxVersions int6
120120
}
121121

122122
rv.Spec = &meshproto.RuleVersion{
123-
ParentRuleKind: string(req.RuleKind),
124-
ParentRuleMesh: extractMesh(req.ResourceKey),
125-
ParentRuleName: extractName(req.ResourceKey),
126-
VersionNo: versionNo,
127-
ContentHash: req.ContentHash,
128-
SpecJson: req.SpecJSON,
129-
Operation: string(req.Operation),
130-
Source: string(req.Source),
131-
Author: req.Author,
132-
Reason: req.Reason,
133-
CreatedAt: timestamppb.New(req.CreatedAt),
134-
CommittedAt: timestamppb.New(committedAt),
123+
ParentRuleKind: string(req.RuleKind),
124+
ParentRuleMesh: extractMesh(req.ResourceKey),
125+
ParentRuleName: extractName(req.ResourceKey),
126+
VersionNo: versionNo,
127+
ContentHash: req.ContentHash,
128+
SpecJson: req.SpecJSON,
129+
Operation: string(req.Operation),
130+
Source: string(req.Source),
131+
Author: req.Author,
132+
Reason: req.Reason,
133+
CreatedAt: timestamppb.New(req.CreatedAt),
134+
CommittedAt: timestamppb.New(committedAt),
135135
}
136136

137137
if req.RolledBackFromID != nil {
@@ -203,18 +203,18 @@ func (a *ResourceStoreAdapter) CreateIntent(req InsertRequest, expectedVersion *
203203
// Create RuleIntent resource
204204
intentRes := meshresource.NewRuleIntentResourceWithAttributes(intentName, req.Mesh)
205205
intentRes.Spec = &meshproto.RuleIntent{
206-
ParentRuleKind: string(req.RuleKind),
207-
ParentRuleMesh: req.Mesh,
208-
ParentRuleName: req.RuleName,
209-
VersionNo: 0, // Will be set on commit
210-
ContentHash: req.ContentHash,
211-
SpecJson: req.SpecJSON,
212-
Operation: string(req.Operation),
213-
Source: string(req.Source),
214-
Author: req.Author,
215-
Reason: req.Reason,
216-
Status: string(IntentStatusPending),
217-
CreatedAt: timestamppb.New(req.CreatedAt),
206+
ParentRuleKind: string(req.RuleKind),
207+
ParentRuleMesh: req.Mesh,
208+
ParentRuleName: req.RuleName,
209+
VersionNo: 0, // Will be set on commit
210+
ContentHash: req.ContentHash,
211+
SpecJson: req.SpecJSON,
212+
Operation: string(req.Operation),
213+
Source: string(req.Source),
214+
Author: req.Author,
215+
Reason: req.Reason,
216+
Status: string(IntentStatusPending),
217+
CreatedAt: timestamppb.New(req.CreatedAt),
218218
}
219219

220220
if req.RolledBackFromID != nil {
@@ -254,8 +254,8 @@ func (a *ResourceStoreAdapter) OpenIntent(kind coremodel.ResourceKind, resourceK
254254
// Find open (pending) intent for this rule
255255
for _, intent := range intents {
256256
if intent.RuleKind == kind &&
257-
intent.ResourceKey == resourceKey &&
258-
intent.Status == IntentStatusPending {
257+
intent.ResourceKey == resourceKey &&
258+
intent.Status == IntentStatusPending {
259259
return &intent, nil
260260
}
261261
}
@@ -295,18 +295,18 @@ func (a *ResourceStoreAdapter) CommitIntent(id int64, maxVersions int64) (*Versi
295295

296296
// Create version from intent
297297
version, err := a.InsertVersion(InsertRequest{
298-
RuleKind: intent.RuleKind,
299-
Mesh: intent.Mesh,
300-
ResourceKey: intent.ResourceKey,
301-
RuleName: intent.RuleName,
302-
SpecJSON: intent.SpecJSON,
303-
ContentHash: intent.ContentHash,
304-
Source: intent.Source,
305-
Operation: intent.Operation,
306-
Author: intent.Author,
307-
Reason: intent.Reason,
308-
CreatedAt: intent.CreatedAt,
309-
RolledBackFromID: intent.RolledBackFromID,
298+
RuleKind: intent.RuleKind,
299+
Mesh: intent.Mesh,
300+
ResourceKey: intent.ResourceKey,
301+
RuleName: intent.RuleName,
302+
SpecJSON: intent.SpecJSON,
303+
ContentHash: intent.ContentHash,
304+
Source: intent.Source,
305+
Operation: intent.Operation,
306+
Author: intent.Author,
307+
Reason: intent.Reason,
308+
CreatedAt: intent.CreatedAt,
309+
RolledBackFromID: intent.RolledBackFromID,
310310
}, maxVersions)
311311
if err != nil {
312312
return nil, err
@@ -349,9 +349,9 @@ func (a *ResourceStoreAdapter) FindOpenIntentByHash(kind coremodel.ResourceKind,
349349

350350
for _, intent := range intents {
351351
if intent.RuleKind == kind &&
352-
intent.ResourceKey == resourceKey &&
353-
intent.ContentHash == contentHash &&
354-
(intent.Status == IntentStatusPending || intent.Status == IntentStatusApplied) {
352+
intent.ResourceKey == resourceKey &&
353+
intent.ContentHash == contentHash &&
354+
(intent.Status == IntentStatusPending || intent.Status == IntentStatusApplied) {
355355
return &intent, nil
356356
}
357357
}

pkg/core/versioning/subscriber.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,22 @@ import (
2323
"time"
2424

2525
"google.golang.org/protobuf/types/known/timestamppb"
26-
"k8s.io/client-go/tools/cache"
2726
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
27+
"k8s.io/client-go/tools/cache"
2828

2929
meshproto "github.com/apache/dubbo-admin/api/mesh/v1alpha1"
3030
"github.com/apache/dubbo-admin/pkg/core/events"
3131
"github.com/apache/dubbo-admin/pkg/core/logger"
3232
"github.com/apache/dubbo-admin/pkg/core/manager"
33-
coremodel "github.com/apache/dubbo-admin/pkg/core/resource/model"
3433
meshresource "github.com/apache/dubbo-admin/pkg/core/resource/apis/mesh/v1alpha1"
34+
coremodel "github.com/apache/dubbo-admin/pkg/core/resource/model"
3535
"github.com/apache/dubbo-admin/pkg/core/store/index"
3636
)
3737

3838
type Subscriber struct {
3939
kind coremodel.ResourceKind
4040
rm manager.ResourceManager
41-
store Store // Still used for Intent matching
41+
store Store // Still used for Intent matching
4242
maxVersions int64
4343
}
4444

@@ -258,7 +258,7 @@ func (s *Subscriber) getNextVersionNo(kind coremodel.ResourceKind, mesh, ruleNam
258258
[]index.IndexCondition{
259259
{
260260
IndexName: index.ByParentRuleIndexName,
261-
Value: fmt.Sprintf("%s/%s/%s", kind, mesh, ruleName),
261+
Value: fmt.Sprintf("%s/%s/%s", kind, mesh, ruleName),
262262
},
263263
},
264264
)
@@ -284,7 +284,7 @@ func (s *Subscriber) checkDuplicateHash(kind coremodel.ResourceKind, mesh, ruleN
284284
[]index.IndexCondition{
285285
{
286286
IndexName: index.ByParentRuleIndexName,
287-
Value: fmt.Sprintf("%s/%s/%s", kind, mesh, ruleName),
287+
Value: fmt.Sprintf("%s/%s/%s", kind, mesh, ruleName),
288288
},
289289
},
290290
)
@@ -314,7 +314,7 @@ func (s *Subscriber) checkDuplicateHash(kind coremodel.ResourceKind, mesh, ruleN
314314
[]index.IndexCondition{
315315
{
316316
IndexName: index.ByParentRuleIndexName,
317-
Value: fmt.Sprintf("%s/%s/%s", kind, mesh, ruleName),
317+
Value: fmt.Sprintf("%s/%s/%s", kind, mesh, ruleName),
318318
},
319319
},
320320
)
@@ -339,14 +339,13 @@ func (s *Subscriber) checkDuplicateHash(kind coremodel.ResourceKind, mesh, ruleN
339339
return true, nil
340340
}
341341

342-
343342
func (s *Subscriber) cleanupOldVersions(kind coremodel.ResourceKind, mesh, ruleName string) error {
344343
resources, err := s.rm.ListByIndexes(
345344
meshresource.RuleVersionKind,
346345
[]index.IndexCondition{
347346
{
348347
IndexName: index.ByParentRuleIndexName,
349-
Value: fmt.Sprintf("%s/%s/%s", kind, mesh, ruleName),
348+
Value: fmt.Sprintf("%s/%s/%s", kind, mesh, ruleName),
350349
},
351350
},
352351
)

pkg/store/dbcommon/gorm_store.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,6 @@ func (gs *GormStore) List() []interface{} {
267267
return result
268268
}
269269

270-
271270
// ListKeys returns all resource keys of the configured kind from the database
272271
func (gs *GormStore) ListKeys() []string {
273272
var keys []string

pkg/store/dbcommon/gorm_store_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -833,11 +833,10 @@ func TestGormStore_ListResourcesSorted(t *testing.T) {
833833
err = store.Add(mockRes2)
834834
require.NoError(t, err)
835835

836-
resources, err := store.ListResources()
837-
require.NoError(t, err)
836+
resources := store.List()
838837
require.Len(t, resources, 2)
839-
assert.Equal(t, "mesh/test-key-1", resources[0].ResourceKey())
840-
assert.Equal(t, "mesh/test-key-2", resources[1].ResourceKey())
838+
assert.Equal(t, "mesh/test-key-1", resources[0].(model.Resource).ResourceKey())
839+
assert.Equal(t, "mesh/test-key-2", resources[1].(model.Resource).ResourceKey())
841840
}
842841

843842
func TestGormStore_PageListByIndexes(t *testing.T) {

pkg/store/memory/store_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,10 @@ func TestResourceStore_ListResourcesSortedAndEmptyIndexes(t *testing.T) {
250250
err = store.Add(mockRes2)
251251
assert.NoError(t, err)
252252

253-
resources, err := store.ListResources()
254-
assert.NoError(t, err)
253+
resources := store.List()
255254
assert.Len(t, resources, 2)
256-
assert.Equal(t, "mesh/test-key-1", resources[0].ResourceKey())
257-
assert.Equal(t, "mesh/test-key-2", resources[1].ResourceKey())
255+
assert.Equal(t, "mesh/test-key-1", resources[0].(model.Resource).ResourceKey())
256+
assert.Equal(t, "mesh/test-key-2", resources[1].(model.Resource).ResourceKey())
258257

259258
indexed, err := store.ListByIndexes([]index.IndexCondition{})
260259
assert.NoError(t, err)

0 commit comments

Comments
 (0)