Skip to content

Commit 410020a

Browse files
Merge pull request #8 from k8snetworkplumbingwg/dev_jrichard
2 parents 2f67cbb + 4f7323b commit 410020a

File tree

2 files changed

+56
-24
lines changed

2 files changed

+56
-24
lines changed

pkg/daemon/daemon.go

+55-24
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"net"
88
"os"
99
"os/exec"
10+
"path/filepath"
1011
"regexp"
1112
"slices"
1213
"strconv"
@@ -56,6 +57,23 @@ var (
5657
clockIDRegEx = regexp.MustCompile(`\/dev\/ptp\d+`)
5758
)
5859

60+
var configPrefix = "/var/run"
61+
62+
var ptpProcesses = []string{
63+
ts2phcProcessName, // there can be only one ts2phc process in the system
64+
syncEProcessName, // there can be only one synce Process per profile
65+
ptp4lProcessName, // there could be more than one ptp4l in the system
66+
phc2sysProcessName, // there can be only one phc2sys process in the system
67+
}
68+
69+
var ptpTmpFiles = []string{
70+
ts2phcProcessName,
71+
syncEProcessName,
72+
ptp4lProcessName,
73+
phc2sysProcessName,
74+
pmcSocketName,
75+
}
76+
5977
// ProcessManager manages a set of ptpProcess
6078
// which could be ptp4l, phc2sys or timemaster.
6179
// Processes in ProcessManager will be started
@@ -81,14 +99,14 @@ func NewProcessManager() *ProcessManager {
8199

82100
// SetTestProfileProcess ...
83101
func (p *ProcessManager) SetTestProfileProcess(name string, ifaces config.IFaces, socketPath,
84-
ptp4lConfigPath string, nodeProfile ptpv1.PtpProfile) {
102+
processConfigPath string, nodeProfile ptpv1.PtpProfile) {
85103
p.process = append(p.process, &ptpProcess{
86-
name: name,
87-
ifaces: ifaces,
88-
ptp4lSocketPath: socketPath,
89-
ptp4lConfigPath: ptp4lConfigPath,
90-
execMutex: sync.Mutex{},
91-
nodeProfile: nodeProfile,
104+
name: name,
105+
ifaces: ifaces,
106+
processSocketPath: socketPath,
107+
processConfigPath: processConfigPath,
108+
execMutex: sync.Mutex{},
109+
nodeProfile: nodeProfile,
92110
})
93111
}
94112

@@ -135,8 +153,8 @@ func (p *ProcessManager) UpdateSynceConfig(config *synce.Relations) {
135153
type ptpProcess struct {
136154
name string
137155
ifaces config.IFaces
138-
ptp4lSocketPath string
139-
ptp4lConfigPath string
156+
processSocketPath string
157+
processConfigPath string
140158
configName string
141159
messageTag string
142160
eventCh chan event.EventChannel
@@ -292,6 +310,24 @@ func (dn *Daemon) SetProcessManager(p *ProcessManager) {
292310
dn.processManager = p
293311
}
294312

313+
// Delete all socket and config files
314+
func (dn *Daemon) cleanupTempFiles() error {
315+
glog.Infof("Cleaning up temporary files")
316+
var err error
317+
for _, p := range ptpTmpFiles {
318+
processWildcard := fmt.Sprintf("%s/%s*", configPrefix, p)
319+
files, _ := filepath.Glob(processWildcard)
320+
for _, file := range files {
321+
err = os.Remove(file)
322+
if err != nil {
323+
glog.Infof("Failed deleting %s", file)
324+
}
325+
}
326+
327+
}
328+
return nil
329+
}
330+
295331
func (dn *Daemon) applyNodePTPProfiles() error {
296332
glog.Infof("in applyNodePTPProfiles")
297333
for _, p := range dn.processManager.process {
@@ -324,6 +360,9 @@ func (dn *Daemon) applyNodePTPProfiles() error {
324360
// references).
325361
dn.processManager.process = nil
326362

363+
// All configs will be rebuild, and sockets recreated, so they can all be deleted
364+
dn.cleanupTempFiles()
365+
327366
// TODO:
328367
// compare nodeProfile with previous config,
329368
// only apply when nodeProfile changes
@@ -433,19 +472,11 @@ ptpconfig profiles for ptp4l
433472
*/
434473
func (dn *Daemon) applyNodePtpProfile(runID int, nodeProfile *ptpv1.PtpProfile) error {
435474
testDir, test := nodeProfile.PtpSettings["unitTest"]
436-
var configPrefix = "/var/run"
437475
if test {
438476
configPrefix = testDir
439477
}
440478
dn.pluginManager.OnPTPConfigChange(nodeProfile)
441479

442-
ptpProcesses := []string{
443-
ts2phcProcessName, // there can be only one ts2phc process in the system
444-
syncEProcessName, // there can be only one synce Process per profile
445-
ptp4lProcessName, // there could be more than one ptp4l in the system
446-
phc2sysProcessName, // there can be only one phc2sys process in the system
447-
}
448-
449480
var err error
450481
var cmdLine string
451482
var configPath string
@@ -594,8 +625,8 @@ func (dn *Daemon) applyNodePtpProfile(runID int, nodeProfile *ptpv1.PtpProfile)
594625
dprocess := ptpProcess{
595626
name: p,
596627
ifaces: ifaces,
597-
ptp4lConfigPath: configPath,
598-
ptp4lSocketPath: socketPath,
628+
processConfigPath: configPath,
629+
processSocketPath: socketPath,
599630
configName: configFile,
600631
messageTag: messageTag,
601632
exitCh: make(chan bool),
@@ -1018,11 +1049,11 @@ func (p *ptpProcess) cmdStop() {
10181049
return
10191050
}
10201051
}
1021-
glog.Infof("removing config path %s for %s ", p.ptp4lConfigPath, p.name)
1022-
if p.ptp4lConfigPath != "" {
1023-
err := os.Remove(p.ptp4lConfigPath)
1052+
glog.Infof("removing config path %s for %s ", p.processConfigPath, p.name)
1053+
if p.processConfigPath != "" {
1054+
err := os.Remove(p.processConfigPath)
10241055
if err != nil {
1025-
glog.Errorf("failed to remove ptp4l config path %s: %v", p.ptp4lConfigPath, err)
1056+
glog.Errorf("failed to remove ptp4l config path %s: %v", p.processConfigPath, err)
10261057
}
10271058
}
10281059
<-p.exitCh
@@ -1109,7 +1140,7 @@ func (dn *Daemon) ApplyHaProfiles(nodeProfile *ptpv1.PtpProfile, cmdLine string)
11091140
for _, profileName := range lsProfiles {
11101141
for _, dmProcess := range dn.processManager.process {
11111142
if dmProcess.nodeProfile.Name != nil && *dmProcess.nodeProfile.Name == profileName {
1112-
updateHaProfileToSocketPath = append(updateHaProfileToSocketPath, "-z "+dmProcess.ptp4lSocketPath)
1143+
updateHaProfileToSocketPath = append(updateHaProfileToSocketPath, "-z "+dmProcess.processSocketPath)
11131144
var ifaces []string
11141145
for _, iface := range dmProcess.ifaces {
11151146
ifaces = append(ifaces, iface.Name)

pkg/daemon/metrics.go

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const (
3131
syncEProcessName = "synce4l"
3232
clockRealTime = "CLOCK_REALTIME"
3333
master = "master"
34+
pmcSocketName = "pmc"
3435

3536
faultyOffset = 999999
3637

0 commit comments

Comments
 (0)