-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use github.com/gofrs/flock to lock handler (#731)
* Use github.com/gofrs/flock to lock handler The nmstate-handler has a lock that make it wait if another handler is already running in the system, but the library used for that does not work well with containers. This change replace that library with different one that uses golang syscall.Flock behind the scine [1] and that works fine with containers sharing node volume. [1] github.com/nightlyone/lockfile. Signed-off-by: Quique Llorente <[email protected]> * Replace handler readiness probe The nmstate handler is marked as ready even if it was not able to take ownership of the lock, this change runs nmstatectl and touchs a file after gaining lock ownership so the readiness probe can check both things. Signed-off-by: Quique Llorente <[email protected]> * Test nmstate handler lock mechanism The nmstate handler don't get ready if another handler is running at the same node. This change add an e2e tests to check that this is working. Signed-off-by: Quique Llorente <[email protected]>
- Loading branch information
Showing
29 changed files
with
1,106 additions
and
614 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package file | ||
|
||
import ( | ||
"os" | ||
"time" | ||
) | ||
|
||
func Touch(fileName string) error { | ||
_, err := os.Stat(fileName) | ||
if os.IsNotExist(err) { | ||
file, err := os.Create(fileName) | ||
if err != nil { | ||
return err | ||
} | ||
defer file.Close() | ||
} else { | ||
currentTime := time.Now().Local() | ||
err = os.Chtimes(fileName, currentTime, currentTime) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.