Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update/lease-namespace #140

Merged
merged 2 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ rules:
- apiGroups: [ "" ]
resources: [ "nodes" ]
verbs: [ "get" ]
- apiGroups: [ "coordination.k8s.io" ]
resources: [ "leases" ]
verbs: [ "create", "get", "delete" ]

---
apiVersion: rbac.authorization.k8s.io/v1
Expand Down Expand Up @@ -230,6 +233,8 @@ OPTIONS:
--release-on-exit release the static public IP address on exit (default: true) [$RELEASE_ON_EXIT]
--retry-attempts value number of attempts to assign the static public IP address (default: 10) [$RETRY_ATTEMPTS]
--retry-interval value when the agent fails to assign the static public IP address, it will retry after this interval (default: 5m0s) [$RETRY_INTERVAL]
--lease-duration value duration of the kubernetes lease (default: 5) [$LEASE_DURATION]
--lease-namespace value namespace of the kubernetes lease (default: "default") [$LEASE_NAMESPACE]

Development

Expand Down
9 changes: 8 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func assignAddress(c context.Context, log *logrus.Entry, client kubernetes.Inter
defer ticker.Stop()

// create new cluster wide lock
lock := lease.NewKubeLeaseLock(client, kubeipLockName, "default", node.Instance, cfg.LeaseDuration)
lock := lease.NewKubeLeaseLock(client, kubeipLockName, cfg.LeaseNamespace, node.Instance, cfg.LeaseDuration)

for retryCounter := 0; retryCounter <= cfg.RetryAttempts; retryCounter++ {
log.WithFields(logrus.Fields{
Expand Down Expand Up @@ -293,6 +293,13 @@ func main() {
EnvVars: []string{"LEASE_DURATION"},
Category: "Configuration",
},
&cli.StringFlag{
Name: "lease-namespace",
Usage: "namespace of the kubernetes lease",
EnvVars: []string{"LEASE_NAMESPACE"},
Value: "default", // default namespace
Category: "Configuration",
},
&cli.BoolFlag{
Name: "release-on-exit",
Usage: "release the static public IP address on exit",
Expand Down
3 changes: 3 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ type Config struct {
ReleaseOnExit bool `json:"release-on-exit"`
// LeaseDuration is the duration of the kubernetes lease
LeaseDuration int `json:"lease-duration"`
// LeaseNamespace is the namespace of the kubernetes lease
LeaseNamespace string `json:"lease-namespace"`
}

func NewConfig(c *cli.Context) *Config {
Expand All @@ -47,5 +49,6 @@ func NewConfig(c *cli.Context) *Config {
cfg.IPv6 = c.Bool("ipv6")
cfg.ReleaseOnExit = c.Bool("release-on-exit")
cfg.LeaseDuration = c.Int("lease-duration")
cfg.LeaseNamespace = c.String("lease-namespace")
return &cfg
}
Loading