Skip to content

Commit

Permalink
Merge pull request #371 from aneeshkp/fix-clock-class-e
Browse files Browse the repository at this point in the history
OCPBUGS-44954: PTP operator Event Notification API breaking change within 4.16 release
  • Loading branch information
openshift-merge-bot[bot] authored Dec 2, 2024
2 parents 7bbec54 + 576414e commit 7a0f127
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 12 deletions.
7 changes: 5 additions & 2 deletions examples/consumer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func main() {
log.Infof("apiVersion=%s, updated apiAddr=%s, apiPath=%s", apiVersion, apiAddr, apiPath)
}

subscribeTo := initSubscribers(consumerType)
subscribeTo := initSubscribers(consumerType, isV1Api)
var wg sync.WaitGroup
wg.Add(1)
go server() // spin local api
Expand Down Expand Up @@ -329,12 +329,15 @@ func processEventV2(data []byte) error {
return nil
}

func initSubscribers(cType ConsumerTypeEnum) map[string]string {
func initSubscribers(cType ConsumerTypeEnum, v1Api bool) map[string]string {
subscribeTo := make(map[string]string)
switch cType {
case PTP:
subscribeTo[string(ptpEvent.OsClockSyncStateChange)] = string(ptpEvent.OsClockSyncState)
subscribeTo[string(ptpEvent.PtpClockClassChange)] = string(ptpEvent.PtpClockClass)
if v1Api {
subscribeTo[string(ptpEvent.PtpClockClassChange)] = string(ptpEvent.PtpClockClassV1)
}
subscribeTo[string(ptpEvent.PtpStateChange)] = string(ptpEvent.PtpLockState)
subscribeTo[string(ptpEvent.GnssStateChange)] = string(ptpEvent.GnssSyncStatus)
subscribeTo[string(ptpEvent.SyncStateChange)] = string(ptpEvent.SyncStatusState)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/onsi/gomega v1.23.0
github.com/prometheus/client_golang v1.14.0
github.com/redhat-cne/rest-api v1.22.0
github.com/redhat-cne/sdk-go v1.22.0
github.com/redhat-cne/sdk-go v1.22.1
github.com/sirupsen/logrus v1.9.0
github.com/stretchr/testify v1.8.1
golang.org/x/net v0.23.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,8 @@ github.com/prometheus/procfs v0.8.0/go.mod h1:z7EfXMXOkbkqb9IINtpCn86r/to3BnA0ua
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/redhat-cne/rest-api v1.22.0 h1:A0IbrLi07eYteFGimhmrOHVD6q1wk3kPKpG4oVAenrk=
github.com/redhat-cne/rest-api v1.22.0/go.mod h1:9Bb+edIo4zJ3/QUwgTWlwP/ZBbtGExxhnAzzLkQLtEA=
github.com/redhat-cne/sdk-go v1.22.0 h1:oAfCu9jjXLn3/aXASuccZCX1Vlz9iIV9pmuO4vy4dSk=
github.com/redhat-cne/sdk-go v1.22.0/go.mod h1:qeir05dwTscLvqGCIoQPCUM6HUoVmhR7521nXn28utA=
github.com/redhat-cne/sdk-go v1.22.1 h1:g5Kuyu92bwEmrjrapK12HvNxzZym+PMh6YhQ0463znw=
github.com/redhat-cne/sdk-go v1.22.1/go.mod h1:qeir05dwTscLvqGCIoQPCUM6HUoVmhR7521nXn28utA=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
Expand Down
20 changes: 15 additions & 5 deletions plugins/ptp_operator/ptp_operator_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func Start(wg *sync.WaitGroup, configuration *common.SCConfiguration, _ func(e i
config = configuration
// register metrics type
ptpMetrics.RegisterMetrics(nodeName)
publishers = InitPubSubTypes()
publishers = InitPubSubTypes(config)

// 1. Create event Publication
var err error
Expand Down Expand Up @@ -201,6 +201,9 @@ func getCurrentStatOverrideFn() func(e v2.Event, d *channel.DataChan) error {
} else if strings.Contains(e.Source(), string(ptp.PtpClockClass)) {
eventType = ptp.PtpClockClassChange
eventSource = ptp.PtpClockClass
} else if strings.Contains(e.Source(), string(ptp.PtpClockClassV1)) {
eventType = ptp.PtpClockClassChange
eventSource = ptp.PtpClockClassV1
} else if strings.Contains(e.Source(), string(ptp.GnssSyncStatus)) {
eventType = ptp.GnssStateChange
eventSource = ptp.GnssSyncStatus
Expand Down Expand Up @@ -633,7 +636,7 @@ func HasEqualInterface(a []*string, b []*ptp4lconf.PTPInterface) bool {
}

// InitPubSubTypes ... initialize types of publishers for ptp operator
func InitPubSubTypes() map[ptp.EventType]*ptpTypes.EventPublisherType {
func InitPubSubTypes(scConfig *common.SCConfiguration) map[ptp.EventType]*ptpTypes.EventPublisherType {
InitPubs := make(map[ptp.EventType]*ptpTypes.EventPublisherType)
InitPubs[ptp.SyncStateChange] = &ptpTypes.EventPublisherType{
EventType: ptp.SyncStateChange,
Expand All @@ -643,9 +646,16 @@ func InitPubSubTypes() map[ptp.EventType]*ptpTypes.EventPublisherType {
EventType: ptp.OsClockSyncStateChange,
Resource: ptp.OsClockSyncState,
}
InitPubs[ptp.PtpClockClassChange] = &ptpTypes.EventPublisherType{
EventType: ptp.PtpClockClassChange,
Resource: ptp.PtpClockClass,
if !common.IsV1Api(scConfig.APIVersion) {
InitPubs[ptp.PtpClockClassChange] = &ptpTypes.EventPublisherType{
EventType: ptp.PtpClockClassChange,
Resource: ptp.PtpClockClass,
}
} else {
InitPubs[ptp.PtpClockClassChange] = &ptpTypes.EventPublisherType{
EventType: ptp.PtpClockClassChange,
Resource: ptp.PtpClockClassV1,
}
}
InitPubs[ptp.PtpStateChange] = &ptpTypes.EventPublisherType{
EventType: ptp.PtpStateChange,
Expand Down
2 changes: 1 addition & 1 deletion plugins/ptp_operator/ptp_operator_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TestMain(m *testing.M) {

c = make(chan os.Signal)
common.StartPubSubService(scConfig)
pubsubTypes = InitPubSubTypes()
pubsubTypes = InitPubSubTypes(scConfig)
cleanUP()
os.Exit(m.Run())
}
Expand Down
4 changes: 4 additions & 0 deletions vendor/github.com/redhat-cne/sdk-go/pkg/event/ptp/resource.go

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

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ github.com/redhat-cne/rest-api
github.com/redhat-cne/rest-api/pkg/localmetrics
github.com/redhat-cne/rest-api/pkg/restclient
github.com/redhat-cne/rest-api/v2
# github.com/redhat-cne/sdk-go v1.22.0
# github.com/redhat-cne/sdk-go v1.22.1
## explicit; go 1.22
github.com/redhat-cne/sdk-go/pkg/channel
github.com/redhat-cne/sdk-go/pkg/common
Expand Down

0 comments on commit 7a0f127

Please sign in to comment.