-
Notifications
You must be signed in to change notification settings - Fork 5k
Implement schedule stop for unix #9503
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
Merged
priyawadhwa
merged 25 commits into
kubernetes:master
from
priyawadhwa:schedule-stop-unix
Nov 12, 2020
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
a54ea82
Implement schedule stop for unix
51b9f68
replace glog with klog
fd425d6
fix klog
202e9c5
improve integration test
682df50
fix lint
b9adc95
Update docs
44f033d
Replace godaemon library with fork
865d3a4
Merge branch 'master' of https://github.com/kubernetes/minikube into …
02f03af
exit if using --schedule with windows as it is not yet supported
a2d00e5
remove my forked dependency now that https://github.com/VividCortex/g…
f869ca5
fix merge conflict
7788cb9
Merge branch 'master' of https://github.com/kubernetes/minikube into …
a00b7a3
Use DurationVar instead of StringVar for flag
129f6d4
go mod tidy
e050e8c
Merge branch 'master' of https://github.com/kubernetes/minikube into …
0ee5a38
update docs
c1be325
Merge branch 'master' of https://github.com/kubernetes/minikube into …
cf1ee6b
Address review comments
635f2a7
fix lint
7570cbd
fix merge
6c48c60
fix docs
bcf236f
don't run scheduled stop test with none driver
9300331
don't try to daemonize none driver
291e5b6
fix merge conflict
5569817
Address code review comments
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,91 @@ | ||
// +build !windows | ||
|
||
/* | ||
Copyright 2020 The Kubernetes Authors All rights reserved. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package schedule | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
"strconv" | ||
"time" | ||
|
||
"github.com/VividCortex/godaemon" | ||
"github.com/pkg/errors" | ||
"k8s.io/klog/v2" | ||
"k8s.io/minikube/pkg/minikube/localpath" | ||
) | ||
|
||
// KillExisting kills existing scheduled stops by looking up the PID | ||
// of the scheduled stop from the PID file saved for the profile and killing the process | ||
func KillExisting(profiles []string) { | ||
for _, profile := range profiles { | ||
if err := killPIDForProfile(profile); err != nil { | ||
klog.Errorf("error killng PID for profile %s: %v", profile, err) | ||
} | ||
} | ||
} | ||
|
||
func killPIDForProfile(profile string) error { | ||
file := localpath.PID(profile) | ||
f, err := ioutil.ReadFile(file) | ||
if os.IsNotExist(err) { | ||
return nil | ||
} | ||
defer func() { | ||
if err := os.Remove(file); err != nil { | ||
klog.Errorf("error deleting %s: %v, you may have to delete in manually", file, err) | ||
} | ||
}() | ||
if err != nil { | ||
return errors.Wrapf(err, "reading %s", file) | ||
} | ||
pid, err := strconv.Atoi(string(f)) | ||
if err != nil { | ||
return errors.Wrapf(err, "converting %s to int", f) | ||
} | ||
p, err := os.FindProcess(pid) | ||
if err != nil { | ||
return errors.Wrap(err, "finding process") | ||
} | ||
klog.Infof("killing process %v as it is an old scheduled stop", pid) | ||
if err := p.Kill(); err != nil { | ||
return errors.Wrapf(err, "killing %v", pid) | ||
} | ||
return nil | ||
} | ||
|
||
func daemonize(profiles []string, duration time.Duration) error { | ||
_, _, err := godaemon.MakeDaemon(&godaemon.DaemonAttr{}) | ||
if err != nil { | ||
return err | ||
} | ||
// now that this process has daemonized, it has a new PID | ||
pid := os.Getpid() | ||
return savePIDs(pid, profiles) | ||
} | ||
|
||
func savePIDs(pid int, profiles []string) error { | ||
for _, p := range profiles { | ||
file := localpath.PID(p) | ||
if err := ioutil.WriteFile(file, []byte(fmt.Sprintf("%v", pid)), 0600); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} |
This file contains hidden or 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,35 @@ | ||
// +build windows | ||
|
||
/* | ||
Copyright 2020 The Kubernetes Authors All rights reserved. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package schedule | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"k8s.io/klog/v2" | ||
) | ||
|
||
// KillExisting will kill existing scheduled stops | ||
func KillExisting(profiles []string) { | ||
klog.Errorf("not yet implemented for windows") | ||
} | ||
|
||
func daemonize(profiles []string, duration time.Duration) error { | ||
return fmt.Errorf("not yet implemented for windows") | ||
} |
This file contains hidden or 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,51 @@ | ||
/* | ||
Copyright 2020 The Kubernetes Authors All rights reserved. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package schedule | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/pkg/errors" | ||
"k8s.io/minikube/pkg/minikube/config" | ||
"k8s.io/minikube/pkg/minikube/driver" | ||
"k8s.io/minikube/pkg/minikube/mustload" | ||
"k8s.io/minikube/pkg/minikube/out" | ||
) | ||
|
||
// Daemonize daemonizes minikube so that scheduled stop happens as expected | ||
func Daemonize(profiles []string, duration time.Duration) error { | ||
// save current time and expected duration in config | ||
scheduledStop := &config.ScheduledStopConfig{ | ||
InitiationTime: time.Now().Unix(), | ||
Duration: duration, | ||
} | ||
var daemonizeProfiles []string | ||
for _, p := range profiles { | ||
_, cc := mustload.Partial(p) | ||
if driver.BareMetal(cc.Driver) { | ||
out.WarningT("scheduled stop is not supported on the none driver, skipping scheduling") | ||
continue | ||
} | ||
daemonizeProfiles = append(daemonizeProfiles, p) | ||
cc.ScheduledStop = scheduledStop | ||
if err := config.SaveProfile(p, cc); err != nil { | ||
return errors.Wrap(err, "saving profile") | ||
} | ||
} | ||
|
||
return daemonize(daemonizeProfiles, duration) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.