From dca2bebe03b605c5bee70ad958cfe4fcea2a426d Mon Sep 17 00:00:00 2001 From: hamistao Date: Wed, 4 Sep 2024 09:34:11 -0300 Subject: [PATCH 1/4] shared/entity: Update `TypeNode` to `TypeClusterMember` Signed-off-by: hamistao --- shared/entity/type.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shared/entity/type.go b/shared/entity/type.go index 53ccda04c7cf..3cf579821fb1 100644 --- a/shared/entity/type.go +++ b/shared/entity/type.go @@ -51,8 +51,8 @@ const ( // TypeNetworkACL represents network acl resources. TypeNetworkACL Type = "network_acl" - // TypeNode represents node resources. - TypeNode Type = "node" + // TypeClusterMember represents node resources. + TypeClusterMember Type = "cluster_member" // TypeOperation represents operation resources. TypeOperation Type = "operation" From 5eb1451278d998a016704c53680f9426cdffe1b5 Mon Sep 17 00:00:00 2001 From: hamistao Date: Wed, 4 Sep 2024 09:34:32 -0300 Subject: [PATCH 2/4] shared: Update `TypeNode` usage Signed-off-by: hamistao --- shared/entity/type.go | 2 +- shared/entity/type_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/shared/entity/type.go b/shared/entity/type.go index 3cf579821fb1..2b12f2945689 100644 --- a/shared/entity/type.go +++ b/shared/entity/type.go @@ -141,7 +141,7 @@ var entityTypes = map[Type]typeInfo{ TypeInstanceSnapshot: instanceSnapshot{}, TypeNetwork: network{}, TypeNetworkACL: networkACL{}, - TypeNode: clusterMember{}, + TypeClusterMember: clusterMember{}, TypeOperation: operation{}, TypeStoragePool: storagePool{}, TypeStorageVolume: storageVolume{}, diff --git a/shared/entity/type_test.go b/shared/entity/type_test.go index 7f0d027bb118..791480fb44c7 100644 --- a/shared/entity/type_test.go +++ b/shared/entity/type_test.go @@ -121,7 +121,7 @@ func TestURL(t *testing.T) { name: "cluster members", rawURL: "/1.0/cluster/members/node01", expectedNormalisedURL: "/1.0/cluster/members/node01", - expectedEntityType: TypeNode, + expectedEntityType: TypeClusterMember, expectedProject: "", expectedPathArgs: []string{"node01"}, expectedErr: nil, From 8ffc7deda66bd81c6a38edf568a23ea4ffafb02f Mon Sep 17 00:00:00 2001 From: hamistao Date: Wed, 4 Sep 2024 09:34:52 -0300 Subject: [PATCH 3/4] lxd: Update `TypeNode` usage Signed-off-by: hamistao --- lxd/cluster/heartbeat.go | 4 ++-- lxd/db/cluster/entities.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lxd/cluster/heartbeat.go b/lxd/cluster/heartbeat.go index 1fbb9c9feba6..a40d8876e97a 100644 --- a/lxd/cluster/heartbeat.go +++ b/lxd/cluster/heartbeat.go @@ -178,7 +178,7 @@ func (hbState *APIHeartbeat) Send(ctx context.Context, networkCert *shared.CertI heartbeatData.Unlock() logger.Debug("Successful heartbeat", logger.Ctx{"remote": address}) - err = warnings.ResolveWarningsByLocalNodeAndProjectAndTypeAndEntity(hbState.cluster, "", warningtype.OfflineClusterMember, entity.TypeNode, int(nodeID)) + err = warnings.ResolveWarningsByLocalNodeAndProjectAndTypeAndEntity(hbState.cluster, "", warningtype.OfflineClusterMember, entity.TypeClusterMember, int(nodeID)) if err != nil { logger.Warn("Failed to resolve warning", logger.Ctx{"err": err}) } @@ -187,7 +187,7 @@ func (hbState *APIHeartbeat) Send(ctx context.Context, networkCert *shared.CertI if ctx.Err() == nil { err = hbState.cluster.Transaction(context.TODO(), func(ctx context.Context, tx *db.ClusterTx) error { - return tx.UpsertWarningLocalNode(ctx, "", entity.TypeNode, int(nodeID), warningtype.OfflineClusterMember, err.Error()) + return tx.UpsertWarningLocalNode(ctx, "", entity.TypeClusterMember, int(nodeID), warningtype.OfflineClusterMember, err.Error()) }) if err != nil { logger.Warn("Failed to create warning", logger.Ctx{"err": err}) diff --git a/lxd/db/cluster/entities.go b/lxd/db/cluster/entities.go index 274d5e5f35a1..01e807234b96 100644 --- a/lxd/db/cluster/entities.go +++ b/lxd/db/cluster/entities.go @@ -82,7 +82,7 @@ var entityTypes = map[entity.Type]entityTypeDBInfo{ entity.TypeInstanceSnapshot: entityTypeInstanceSnapshot{}, entity.TypeNetwork: entityTypeNetwork{}, entity.TypeNetworkACL: entityTypeNetworkACL{}, - entity.TypeNode: entityTypeClusterMember{}, + entity.TypeClusterMember: entityTypeClusterMember{}, entity.TypeOperation: entityTypeOperation{}, entity.TypeStoragePool: entityTypeStoragePool{}, entity.TypeStorageVolume: entityTypeStorageVolume{}, From 044bb4ac946c15b387db5fa18fe89d4f0559b258 Mon Sep 17 00:00:00 2001 From: hamistao Date: Wed, 4 Sep 2024 09:59:23 -0300 Subject: [PATCH 4/4] lxd/cluster: Use `NewStatusError` Signed-off-by: hamistao --- lxd/cluster/heartbeat.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lxd/cluster/heartbeat.go b/lxd/cluster/heartbeat.go index a40d8876e97a..4da07bbfda70 100644 --- a/lxd/cluster/heartbeat.go +++ b/lxd/cluster/heartbeat.go @@ -557,7 +557,7 @@ func HeartbeatNode(taskCtx context.Context, address string, networkCert *shared. defer func() { _ = response.Body.Close() }() if response.StatusCode != http.StatusOK { - return fmt.Errorf("Heartbeat request failed with status: %w", api.StatusErrorf(response.StatusCode, response.Status)) + return fmt.Errorf("Heartbeat request failed with status: %w", api.NewStatusError(response.StatusCode, response.Status)) } return nil