Skip to content

Commit a242820

Browse files
committed
debug e2e
Signed-off-by: root <[email protected]>
1 parent 08b5078 commit a242820

File tree

5 files changed

+48
-7
lines changed

5 files changed

+48
-7
lines changed

agent/pkg/spec/syncers/clusterlabel_syncer.go

+7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import (
2020
"github.com/stolostron/multicluster-global-hub/pkg/utils"
2121
)
2222

23+
var log = logger.DefaultZapLogger()
24+
2325
const (
2426
// periodicApplyInterval = 5 * time.Second
2527
hohFieldManager = "mgh-agent"
@@ -51,6 +53,7 @@ func (syncer *managedClusterLabelsBundleSyncer) Sync(ctx context.Context, payloa
5153
if err := json.Unmarshal(payload, bundle); err != nil {
5254
return err
5355
}
56+
syncer.log.Debugf("start sync bundle: %v", bundle)
5457
syncer.setLatestBundle(bundle) // uses latestBundle
5558
syncer.handleBundle()
5659

@@ -69,6 +72,8 @@ func (syncer *managedClusterLabelsBundleSyncer) handleBundle() {
6972
defer syncer.latestBundleLock.Unlock()
7073

7174
for _, managedClusterLabelsSpec := range syncer.latestBundle.Objects {
75+
log.Debugf("managedClusterLabelsSpec:%v", *managedClusterLabelsSpec)
76+
7277
lastProcessedTimestampPtr := syncer.getManagedClusterLastProcessedTimestamp(managedClusterLabelsSpec.ClusterName)
7378
if managedClusterLabelsSpec.UpdateTimestamp.After(*lastProcessedTimestampPtr) { // handle (success) once
7479
syncer.bundleProcessingWaitingGroup.Add(1)
@@ -115,11 +120,13 @@ func (s *managedClusterLabelsBundleSyncer) updateManagedClusterAsync(
115120
for key, value := range labelsSpec.Labels {
116121
managedCluster.Labels[key] = value
117122
}
123+
log.Debugf("managedCluster.Labels: %v", managedCluster.Labels)
118124

119125
// delete labels by key
120126
for _, labelKey := range labelsSpec.DeletedLabelKeys {
121127
delete(managedCluster.Labels, labelKey)
122128
}
129+
log.Debugf("managedCluster.Labels: %v", managedCluster.Labels)
123130

124131
if err := s.updateManagedFieldEntry(managedCluster, labelsSpec); err != nil {
125132
s.log.Error(err, "failed to update managed cluster", "name", labelsSpec.ClusterName)

agent/pkg/status/generic/generic_handler.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ import (
66

77
"github.com/stolostron/multicluster-global-hub/agent/pkg/status/interfaces"
88
genericpayload "github.com/stolostron/multicluster-global-hub/pkg/bundle/generic"
9+
"github.com/stolostron/multicluster-global-hub/pkg/logger"
910
)
1011

12+
var log = logger.ZapLogger("generic-handler")
13+
1114
type genericHandler struct {
1215
eventData *genericpayload.GenericObjectBundle
1316
// isSpec is to let the handler only update the event when spec is changed.
@@ -32,23 +35,28 @@ func NewGenericHandler(eventData *genericpayload.GenericObjectBundle, opts ...Ha
3235
}
3336

3437
func (h *genericHandler) Get() interface{} {
38+
log.Debugf("get obj:%v", h.eventData)
3539
return h.eventData
3640
}
3741

3842
func (h *genericHandler) Update(obj client.Object) bool {
43+
log.Debugf("update obj:%v", obj)
44+
3945
if h.shouldUpdate != nil {
4046
if updated := h.shouldUpdate(obj); !updated {
47+
log.Debugf("h.shouldUpdate false")
4148
return false
4249
}
4350
}
44-
4551
index := getObjectIndexByUID(obj.GetUID(), (*h.eventData))
4652
if index == -1 { // object not found, need to add it to the bundle
4753
(*h.eventData) = append((*h.eventData), obj)
4854
return true
4955
}
5056

5157
old := (*h.eventData)[index]
58+
log.Debugf("obj: %v", old)
59+
5260
if h.isSpec && old.GetGeneration() == obj.GetGeneration() {
5361
return false
5462
}
@@ -121,6 +129,8 @@ func WithSpec(onlySpec bool) HandlerOption {
121129
}
122130

123131
func WithShouldUpdate(shouldUpdate func(client.Object) bool) HandlerOption {
132+
log.Debugf("g.shouldUpdate:%v, shouldUpdate:%v", shouldUpdate, shouldUpdate)
133+
124134
return func(g *genericHandler) {
125135
g.shouldUpdate = shouldUpdate
126136
}

manager/pkg/spec/syncers/managedcluster_labels_syncer.go

+4
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,14 @@ func getUpdatedManagedClusterLabelsBundles(timestamp *time.Time,
105105
func getManagedClusterLabelBundleByRows(db *gorm.DB, rows *sql.Rows) (
106106
map[string]*spec.ManagedClusterLabelsSpecBundle, error,
107107
) {
108+
log.Debugf("getManagedClusterLabelBundleByRows")
108109
leafHubToLabelsSpecBundleMap := make(map[string]*spec.ManagedClusterLabelsSpecBundle)
109110
for rows.Next() {
110111
managedClusterLabel := models.ManagedClusterLabel{}
111112
if err := db.ScanRows(rows, &managedClusterLabel); err != nil {
112113
return nil, fmt.Errorf("error reading managed cluster label from table - %w", err)
113114
}
115+
log.Debugf("managedClusterLabel: %v", managedClusterLabel)
114116

115117
// create ManagedClusterLabelsSpecBundle if not mapped for leafHub
116118
managedClusterLabelsSpecBundle, found := leafHubToLabelsSpecBundleMap[managedClusterLabel.LeafHubName]
@@ -127,12 +129,14 @@ func getManagedClusterLabelBundleByRows(db *gorm.DB, rows *sql.Rows) (
127129
if err != nil {
128130
return nil, fmt.Errorf("error to unmarshal labels - %w", err)
129131
}
132+
log.Debugf("labels: %v", labels)
130133

131134
deletedKeys := []string{}
132135
err = json.Unmarshal(managedClusterLabel.DeletedLabelKeys, &deletedKeys)
133136
if err != nil {
134137
return nil, fmt.Errorf("error to unmarshal deletedKeys - %w", err)
135138
}
139+
log.Debugf("deletedKeys: %v", deletedKeys)
136140

137141
managedClusterLabelsSpecBundle.Objects = append(managedClusterLabelsSpecBundle.Objects,
138142
&spec.ManagedClusterLabelsSpec{

manager/pkg/spec/syncers/managedcluster_labels_watcher.go

+12-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import (
1818
"github.com/stolostron/multicluster-global-hub/pkg/logger"
1919
)
2020

21+
var log = logger.ZapLogger("labels-watcher")
22+
2123
const (
2224
labelsTableName = "managed_clusters_labels"
2325
clusterTableName = "managed_clusters"
@@ -66,7 +68,7 @@ func (watcher *managedClusterLabelsStatusWatcher) updateDeletedLabelsPeriodicall
6668
return
6769

6870
case <-labelsTrimmerTicker.C:
69-
71+
log.Debugf("labelsTrimmerTicker")
7072
_, cancelFunc := context.WithTimeout(ctx, watcher.intervalPolicy.GetMaxInterval())
7173

7274
// update the deleted label keys to label table by the managed cluster table
@@ -106,10 +108,12 @@ func (watcher *managedClusterLabelsStatusWatcher) updateDeletedLabelsPeriodicall
106108

107109
func (watcher *managedClusterLabelsStatusWatcher) updateDeletedLabelsByManagedCluster() bool {
108110
leafHubToLabelsSpecBundleMap, err := getLabelBundleWithDeletedKey()
111+
log.Debugf("leafHubToLabelsSpecBundleMap: %v, err: %v", leafHubToLabelsSpecBundleMap, err)
109112
if err != nil {
110113
watcher.log.Error(err, "trimming cycle skipped")
111114
return false
112115
}
116+
log.Debugf("updateDeletedLabelsByManagedCluster")
113117
conn := database.GetConn()
114118
err = database.Lock(conn)
115119
if err != nil {
@@ -120,9 +124,12 @@ func (watcher *managedClusterLabelsStatusWatcher) updateDeletedLabelsByManagedCl
120124

121125
result := true
122126
// iterate over entries
127+
log.Debugf("updateDeletedLabelsByManagedCluster")
128+
123129
for _, managedClusterLabelsSpecBundle := range leafHubToLabelsSpecBundleMap {
124130
// fetch actual labels status reflected in status DB
125131
for _, managedClusterLabelsSpec := range managedClusterLabelsSpecBundle.Objects {
132+
log.Debugf("managedClusterLabelsSpec: %v", managedClusterLabelsSpec)
126133
labelsStatus, err := getLabelsFromManagedCluster(managedClusterLabelsSpecBundle.LeafHubName,
127134
managedClusterLabelsSpec.ClusterName)
128135
if err != nil {
@@ -153,13 +160,16 @@ func (watcher *managedClusterLabelsStatusWatcher) updateDeletedLabelsByManagedCl
153160
result = false
154161
continue
155162
}
163+
log.Debugf("update label table by managed cluster table successfully", "leafHub",
164+
managedClusterLabelsSpecBundle.LeafHubName,
165+
"managedCluster", managedClusterLabelsSpec.ClusterName, "version", managedClusterLabelsSpec.Version)
156166

157167
watcher.log.Debugw("update label table by managed cluster table successfully", "leafHub",
158168
managedClusterLabelsSpecBundle.LeafHubName,
159169
"managedCluster", managedClusterLabelsSpec.ClusterName, "version", managedClusterLabelsSpec.Version)
160170
}
161171
}
162-
172+
log.Debugf("result: %v", result)
163173
return result
164174
}
165175

test/e2e/cluster_test.go

+14-4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
corev1 "k8s.io/api/core/v1"
1515
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1616
"k8s.io/apimachinery/pkg/types"
17+
"k8s.io/klog"
1718
addonapiv1alpha1 "open-cluster-management.io/api/addon/v1alpha1"
1819
clusterv1 "open-cluster-management.io/api/cluster/v1"
1920
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -87,7 +88,7 @@ var _ = Describe("Managed Clusters", Label("e2e-test-cluster"), Ordered, func()
8788
return fmt.Errorf("want messsage %s, got %s", eventMessage, clusterEvent.Message)
8889
}
8990
return nil
90-
}, 3*time.Minute, 1*time.Second).ShouldNot(HaveOccurred())
91+
}, 3*time.Minute, 10*time.Second).ShouldNot(HaveOccurred())
9192

9293
By("Delete the cluster event from the leafhub")
9394
Expect(hubClient.Delete(ctx, clusterEvent)).To(Succeed())
@@ -273,8 +274,10 @@ func getManagedClusterByName(client *http.Client, managedClusterName string) (
273274
if err != nil {
274275
return nil, err
275276
}
276-
277+
klog.Infof("len(managedClusterList):%v \n", len(managedClusterList.Items))
277278
for _, managedCluster := range managedClusterList.Items {
279+
klog.Infof("managedcluster: %v, label: %v \n", managedCluster.Name, managedCluster.Labels)
280+
klog.Infof("managedClusterName: %v \n", managedClusterName)
278281
if managedCluster.Name == managedClusterName {
279282
return &managedCluster, nil
280283
}
@@ -292,6 +295,7 @@ func assertAddLabel(cluster clusterv1.ManagedCluster, labelKey, labelVal string)
292295
},
293296
}
294297
By("Check the label is added")
298+
count := 1
295299
Eventually(func() error {
296300
err := updateClusterLabelByAPI(httpClient, patches, GetClusterID(cluster))
297301
if err != nil {
@@ -306,8 +310,14 @@ func assertAddLabel(cluster clusterv1.ManagedCluster, labelKey, labelVal string)
306310
return nil
307311
}
308312
}
313+
count++
314+
if count > 150 {
315+
time.Sleep(200 * time.Minute)
316+
}
317+
klog.Infof("count: %v\n", count)
318+
klog.Infof("failed to add label [%s: %s] to cluster %s \n", labelKey, labelVal, cluster.Name)
309319
return fmt.Errorf("failed to add label [%s: %s] to cluster %s", labelKey, labelVal, cluster.Name)
310-
}, 3*time.Minute, 1*time.Second).ShouldNot(HaveOccurred())
320+
}, 3*time.Minute, 10*time.Second).ShouldNot(HaveOccurred())
311321
}
312322

313323
func assertRemoveLabel(cluster clusterv1.ManagedCluster, labelKey, labelVal string) {
@@ -334,7 +344,7 @@ func assertRemoveLabel(cluster clusterv1.ManagedCluster, labelKey, labelVal stri
334344
}
335345
}
336346
return nil
337-
}, 3*time.Minute, 1*time.Second).ShouldNot(HaveOccurred())
347+
}, 3*time.Minute, 10*time.Second).ShouldNot(HaveOccurred())
338348
}
339349

340350
func updateClusterLabelByAPI(client *http.Client, patches []patch, managedClusterID string) error {

0 commit comments

Comments
 (0)