-
Notifications
You must be signed in to change notification settings - Fork 771
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: mingzhou.swx <mingzhou.swx@alibaba-inc.com>
- Loading branch information
mingzhou.swx
committed
Jun 20, 2023
1 parent
6d25366
commit 5c941c8
Showing
10 changed files
with
297 additions
and
6 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
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,38 @@ | ||
package revision | ||
|
||
import ( | ||
"strings" | ||
|
||
appspub "github.com/openkruise/kruise/apis/apps/pub" | ||
"github.com/openkruise/kruise/pkg/features" | ||
utilfeature "github.com/openkruise/kruise/pkg/util/feature" | ||
"github.com/openkruise/kruise/pkg/util/lifecycle" | ||
apps "k8s.io/api/apps/v1" | ||
v1 "k8s.io/api/core/v1" | ||
) | ||
|
||
// IsPodUpdate return true when: | ||
// - Pod controller-revision-hash equals to updateRevision; | ||
// - Pod at preparing update state if PreparingUpdateAsUpdate feature-gated is enabled. | ||
func IsPodUpdate(pod *v1.Pod, updateRevision string) bool { | ||
if utilfeature.DefaultFeatureGate.Enabled(features.PreparingUpdateAsUpdate) && | ||
lifecycle.GetPodLifecycleState(pod) == appspub.LifecycleStatePreparingUpdate { | ||
return true | ||
} | ||
return equalToRevisionHash("", pod, updateRevision) | ||
} | ||
|
||
func equalToRevisionHash(s string, pod *v1.Pod, hash string) bool { | ||
objHash := pod.GetLabels()[apps.ControllerRevisionHashLabelKey] | ||
if objHash == hash { | ||
return true | ||
} | ||
return getShortHash(hash) == getShortHash(objHash) | ||
} | ||
|
||
func getShortHash(hash string) string { | ||
// This makes sure the real hash must be the last '-' substring of revision name | ||
// vendor/k8s.io/kubernetes/pkg/controller/history/controller_history.go#82 | ||
list := strings.Split(hash, "-") | ||
return list[len(list)-1] | ||
} |
Oops, something went wrong.