Skip to content

Commit

Permalink
syncset testing
Browse files Browse the repository at this point in the history
  • Loading branch information
rhamitarora committed Sep 3, 2024
1 parent 0684a5a commit ec7dd93
Show file tree
Hide file tree
Showing 16 changed files with 783 additions and 6 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ require (
github.com/openshift/api v0.0.0-20240103200955-7ca3a4634e46
github.com/openshift/client-go v0.0.0-20221019143426-16aed247da5c
github.com/openshift/cloud-credential-operator v0.0.0-00010101000000-000000000000
github.com/openshift/hive/apis v0.0.0-20240627073933-b1ac27b24815
github.com/openshift/hive/apis v0.0.0-20240829000349-95efcb7a0a11
github.com/openshift/library-go v0.0.0-20220525173854-9b950a41acdc
github.com/openshift/machine-config-operator v0.0.1-0.20230519222939-1abc13efbb0d
github.com/pires/go-proxyproto v0.6.2
Expand Down
19 changes: 19 additions & 0 deletions pkg/hive/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"errors"
"fmt"
"log"
"sort"

hivev1 "github.com/openshift/hive/apis/hive/v1"
Expand All @@ -24,6 +25,7 @@ import (
"github.com/Azure/ARO-RP/pkg/hive/failure"
"github.com/Azure/ARO-RP/pkg/util/dynamichelper"
utillog "github.com/Azure/ARO-RP/pkg/util/log"
hivev1alpha1 "github.com/openshift/hive/apis/hiveinternal/v1alpha1"
)

type ClusterManager interface {
Expand All @@ -42,6 +44,7 @@ type ClusterManager interface {
IsClusterInstallationComplete(ctx context.Context, doc *api.OpenShiftClusterDocument) (bool, error)
GetClusterDeployment(ctx context.Context, doc *api.OpenShiftClusterDocument) (*hivev1.ClusterDeployment, error)
ResetCorrelationData(ctx context.Context, doc *api.OpenShiftClusterDocument) error
GetSyncSetResources(ctx context.Context, doc *api.OpenShiftClusterDocument) (*hivev1alpha1.ClusterSync, error)
}

type clusterManager struct {
Expand Down Expand Up @@ -263,3 +266,19 @@ func (hr *clusterManager) installLogsForLatestDeployment(ctx context.Context, cd

return latestProvision.Spec.InstallLog, nil
}

func (hr *clusterManager) GetSyncSetResources(ctx context.Context, doc *api.OpenShiftClusterDocument) (*hivev1alpha1.ClusterSync, error) {
clusterSync := &hivev1alpha1.ClusterSync{}

key := client.ObjectKey{
Name: ClusterDeploymentName, // "cluster",
Namespace: doc.OpenShiftCluster.Properties.HiveProfile.Namespace,
}

err := hr.hiveClientset.Get(ctx, key, clusterSync)
if err != nil {
log.Fatalf("Error getting ClusterSync resources: %s", err.Error())
}

return clusterSync, nil
}
8 changes: 6 additions & 2 deletions pkg/monitor/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"

"github.com/Azure/ARO-RP/pkg/api"
"github.com/Azure/ARO-RP/pkg/hive"
"github.com/Azure/ARO-RP/pkg/metrics"
"github.com/Azure/ARO-RP/pkg/monitor/dimension"
"github.com/Azure/ARO-RP/pkg/monitor/emitter"
Expand Down Expand Up @@ -60,10 +61,12 @@ type Monitor struct {
arodl *appsv1.DeploymentList
}

wg *sync.WaitGroup
wg *sync.WaitGroup
hiveClusterManager hive.ClusterManager
doc *api.OpenShiftClusterDocument
}

func NewMonitor(log *logrus.Entry, restConfig *rest.Config, oc *api.OpenShiftCluster, m metrics.Emitter, hiveRestConfig *rest.Config, hourlyRun bool, wg *sync.WaitGroup) (*Monitor, error) {
func NewMonitor(log *logrus.Entry, restConfig *rest.Config, oc *api.OpenShiftCluster, doc *api.OpenShiftClusterDocument, m metrics.Emitter, hiveRestConfig *rest.Config, hourlyRun bool, wg *sync.WaitGroup, hiveClusterManager hive.ClusterManager) (*Monitor, error) {
r, err := azure.ParseResourceID(oc.ID)
if err != nil {
return nil, err
Expand Down Expand Up @@ -188,6 +191,7 @@ func (mon *Monitor) Monitor(ctx context.Context) (errs []error) {
return
}
for _, f := range []func(context.Context) error{
mon.emitSyncSetStatus,
mon.emitAroOperatorHeartbeat,
mon.emitAroOperatorConditions,
mon.emitNSGReconciliation,
Expand Down
46 changes: 46 additions & 0 deletions pkg/monitor/cluster/syncsetstatus.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package cluster

// Copyright (c) Microsoft Corporation.
// Licensed under the Apache License 2.0.

import (
"context"
"fmt"
)

func (mon *Monitor) emitSyncSetStatus(ctx context.Context) error {
cs, error := mon.hiveClusterManager.GetSyncSetResources(ctx, mon.doc)
if error != nil {
return nil
}

fmt.Println("syncsets")
if cs.Status.SyncSets != nil {
mon.emitGauge("syncsets.count", int64(len(cs.Status.SyncSets)), nil)

for _, s := range cs.Status.SyncSets {
mon.emitGauge("hive.syncsets", 1, map[string]string{
"name": s.Name,
"result": string(s.Result),
"firstSuccessTime": s.FirstSuccessTime.String(),
"lastTransitionTime": s.LastTransitionTime.String(),
"failureMessage": s.FailureMessage,
})
}
}

if cs.Status.SelectorSyncSets != nil {
mon.emitGauge("selectorsyncsets.count", int64(len(cs.Status.SelectorSyncSets)), nil)

for _, s := range cs.Status.SelectorSyncSets {
mon.emitGauge("hive.selectorsyncsets", 1, map[string]string{
"name": s.Name,
"result": string(s.Result),
"firstSuccessTime": s.FirstSuccessTime.String(),
"lastTransitionTime": s.LastTransitionTime.String(),
"failureMessage": s.FailureMessage,
})
}
}
return nil
}
11 changes: 10 additions & 1 deletion pkg/monitor/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
"k8s.io/client-go/rest"

"github.com/Azure/ARO-RP/pkg/api"
"github.com/Azure/ARO-RP/pkg/env"
"github.com/Azure/ARO-RP/pkg/hive"
"github.com/Azure/ARO-RP/pkg/monitor/azure/nsg"
"github.com/Azure/ARO-RP/pkg/monitor/cluster"
"github.com/Azure/ARO-RP/pkg/monitor/dimension"
Expand Down Expand Up @@ -283,7 +285,14 @@ func (mon *monitor) workOne(ctx context.Context, log *logrus.Entry, doc *api.Ope

nsgMon := nsg.NewMonitor(log, doc.OpenShiftCluster, mon.env, sub.ID, sub.Subscription.Properties.TenantID, mon.clusterm, dims, &wg, nsgMonTicker.C)

c, err := cluster.NewMonitor(log, restConfig, doc.OpenShiftCluster, mon.clusterm, hiveRestConfig, hourlyRun, &wg)
_env, err := env.NewEnv(ctx, log, env.COMPONENT_MONITOR)
if err != nil {
log.Error(err)
return
}
hiveClusterManager, _ := hive.NewFromConfig(log, _env, restConfig)
c, err := cluster.NewMonitor(log, restConfig, doc.OpenShiftCluster, doc, mon.clusterm, hiveRestConfig, hourlyRun, &wg, hiveClusterManager)

if err != nil {
log.Error(err)
mon.m.EmitGauge("monitor.cluster.failedworker", 1, map[string]string{
Expand Down
16 changes: 16 additions & 0 deletions pkg/util/mocks/hive/hive.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pkg/util/scheme/scheme.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
securityv1 "github.com/openshift/api/security/v1"
cloudcredentialv1 "github.com/openshift/cloud-credential-operator/pkg/apis/cloudcredential/v1"
hivev1 "github.com/openshift/hive/apis/hive/v1"
hivev1alpha1 "github.com/openshift/hive/apis/hiveinternal/v1alpha1"
mcv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1"
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
appsv1 "k8s.io/api/apps/v1"
Expand Down Expand Up @@ -51,6 +52,7 @@ func init() {
utilruntime.Must(operatorv1.AddToScheme(scheme.Scheme))
utilruntime.Must(cloudcredentialv1.AddToScheme(scheme.Scheme))
utilruntime.Must(hivev1.AddToScheme(scheme.Scheme))
utilruntime.Must(hivev1alpha1.AddToScheme(scheme.Scheme))
utilruntime.Must(imageregistryv1.AddToScheme(scheme.Scheme))
utilruntime.Must(templatesv1.AddToScheme(scheme.Scheme))
}
1 change: 1 addition & 0 deletions pull-secret.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"auths":{"cloud.openshift.com":{"auth":"b3Bl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JQMkt4VXpaeXVJdTMtNWxDc0xGMGg5MEZfTkpkYThsc1VPOHlHZndFZzl5amUxdWg0WVh4ZUpCNjVLOEwyMjJpYk52YmdnY0VlRDVyaWNRZVpuVVZyeWF5aVNaQW1LZXpkbFdVcDZiTGtJWGxSeC1iQ0pzaVQ2LS1TbWpjZl9pdVVoUzhmdU5QekZYWlV4aHVqN3hPaTd2VTJGdVN0T01HTnQ3X2hMTWJRSzZqTjVSMkpKQ1dVMUp5eWtUSmNFal9TMW11d0hNbG80c0YwUmdOVi1Vbm5VSGhITENaZS1iNG1xS3ExQVl5emxxYl9QOFJXRm5OX1ROcVZlSG5sWkVTN1Z1SmZRblZFZU85VTdyT29iQUJQU3NDRjFRVXl2UUNuejBlZndNa0wzRUZLMzIxUmJ3cXFDN0c0cjVmVExYV0h4Zm9tUTZhcDRKMUhRemVHd29ya0d0RUNtV1lPQjY3OEozWWhaS3RyQ3MydURLdw==","email":"amarora@redhat.com"}}}
4 changes: 3 additions & 1 deletion test/e2e/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ var _ = Describe("Monitor", func() {
wg.Add(1)
mon, err := cluster.NewMonitor(log, clients.RestConfig, &api.OpenShiftCluster{
ID: resourceIDFromEnv(),
}, &noop.Noop{}, nil, true, &wg)
}, &api.OpenShiftClusterDocument{
ID: resourceIDFromEnv(),
}, &noop.Noop{}, nil, true, &wg, nil)
Expect(err).NotTo(HaveOccurred())

By("running the monitor once")
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ec7dd93

Please sign in to comment.