This repository has been archived by the owner on Jul 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
add gardenctl hibernate and gardenctl wakeup to hibernate/wakeup shoot cluster #465
Open
neo-liang-sap
wants to merge
5
commits into
gardener-attic:master
Choose a base branch
from
neo-liang-sap:gardenctl-wakeup-hibernate
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7d76629
add gardenctl hibernate and gardenctl wakeup to hibernate/wakeup shoo…
neo-liang-sap 0be3967
fix check errors
neo-liang-sap d26e6ac
some fix according to review comments
neo-liang-sap 8a0da1e
use get to get shoot
neo-liang-sap 4c71a05
fix check error
neo-liang-sap 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 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,66 @@ | ||
// Copyright (c) 2018 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file | ||
// | ||
// 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 cmd | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"os" | ||
"time" | ||
|
||
"github.com/gardener/gardener/pkg/apis/core/v1beta1" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// NewHibernateCmd returns diagnostic information for a shoot. | ||
func NewHibernateCmd(reader TargetReader, ioStreams IOStreams) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "hibernate", | ||
Short: "Hibernate a cluster if wakeup-able and shoot is wakeup", | ||
SilenceUsage: true, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
target := reader.ReadTarget(pathTarget) | ||
if !CheckShootIsTargeted(target) { | ||
return errors.New("no shoot targeted") | ||
} | ||
|
||
shoot, err := FetchShootFromTarget(target) | ||
checkError(err) | ||
hibernateShoot(shoot, reader) | ||
return nil | ||
}, | ||
} | ||
return cmd | ||
} | ||
|
||
func hibernateShoot(shoot *v1beta1.Shoot, reader TargetReader) { | ||
if shoot.Spec.Hibernation != nil && shoot.Spec.Hibernation.Enabled != nil && *shoot.Spec.Hibernation.Enabled { | ||
fmt.Println("shoot already hibernated!") | ||
os.Exit(0) | ||
} | ||
|
||
//hibernate the shoot | ||
newShoot := shoot.DeepCopy() | ||
setHibernation(newShoot, true) | ||
patchedShoot, err := MergePatchShoot(shoot, newShoot, reader) | ||
checkError(err) | ||
*shoot = *patchedShoot | ||
|
||
time.Sleep(time.Second * 20) | ||
|
||
//wait for shoot to be reconciled in 20 mins | ||
err = waitShootReconciled(shoot, reader) | ||
checkError(err) | ||
} |
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,66 @@ | ||
// Copyright (c) 2018 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file | ||
// | ||
// 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 cmd | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"os" | ||
"time" | ||
|
||
"github.com/gardener/gardener/pkg/apis/core/v1beta1" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// NewWakeupCmd returns diagnostic information for a shoot. | ||
func NewWakeupCmd(reader TargetReader, ioStreams IOStreams) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "wakeup", | ||
Short: "Wake up a cluster if wakeup-able and shoot is hibernated", | ||
SilenceUsage: true, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
target := reader.ReadTarget(pathTarget) | ||
if !CheckShootIsTargeted(target) { | ||
return errors.New("no shoot targeted") | ||
} | ||
|
||
shoot, err := FetchShootFromTarget(target) | ||
checkError(err) | ||
wakeupShoot(shoot, reader) | ||
return nil | ||
}, | ||
} | ||
return cmd | ||
} | ||
|
||
func wakeupShoot(shoot *v1beta1.Shoot, reader TargetReader) { | ||
if shoot.Spec.Hibernation == nil || shoot.Spec.Hibernation.Enabled == nil || !*shoot.Spec.Hibernation.Enabled { | ||
fmt.Println("Shoot already wakeup") | ||
os.Exit(0) | ||
} | ||
|
||
//wakeup the shoot | ||
newShoot := shoot.DeepCopy() | ||
setHibernation(newShoot, false) | ||
patchedShoot, err := MergePatchShoot(shoot, newShoot, reader) | ||
checkError(err) | ||
*shoot = *patchedShoot | ||
|
||
time.Sleep(time.Second * 20) | ||
|
||
//wait for shoot to be reconciled in 20 mins | ||
err = waitShootReconciled(shoot, reader) | ||
checkError(err) | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will overwrite hibernation schedule.