-
Notifications
You must be signed in to change notification settings - Fork 520
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from stakater/rollback-upgrade-deployment
[STK-322] Rollback upgrade deployment
- Loading branch information
Showing
23 changed files
with
2,087 additions
and
238 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,5 @@ release | |
out/ | ||
_gopath/ | ||
.DS_Store | ||
.vscode | ||
vendor |
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 |
---|---|---|
@@ -1 +1 @@ | ||
0.0.1 | ||
0.0.1 |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,91 @@ | ||
package callbacks | ||
|
||
import ( | ||
"github.com/sirupsen/logrus" | ||
"github.com/stakater/Reloader/internal/pkg/util" | ||
apps_v1beta1 "k8s.io/api/apps/v1beta1" | ||
"k8s.io/api/core/v1" | ||
"k8s.io/api/extensions/v1beta1" | ||
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/client-go/kubernetes" | ||
) | ||
|
||
//ItemsFunc is a generic function to return a specific resource array in given namespace | ||
type ItemsFunc func(kubernetes.Interface, string) []interface{} | ||
|
||
//ContainersFunc is a generic func to return containers | ||
type ContainersFunc func(interface{}) []v1.Container | ||
|
||
//UpdateFunc performs the resource update | ||
type UpdateFunc func(kubernetes.Interface, string, interface{}) error | ||
|
||
//RollingUpgradeFuncs contains generic functions to perform rolling upgrade | ||
type RollingUpgradeFuncs struct { | ||
ItemsFunc ItemsFunc | ||
ContainersFunc ContainersFunc | ||
UpdateFunc UpdateFunc | ||
ResourceType string | ||
} | ||
|
||
// GetDeploymentItems returns the deployments in given namespace | ||
func GetDeploymentItems(client kubernetes.Interface, namespace string) []interface{} { | ||
deployments, err := client.ExtensionsV1beta1().Deployments(namespace).List(meta_v1.ListOptions{}) | ||
if err != nil { | ||
logrus.Errorf("Failed to list deployments %v", err) | ||
} | ||
return util.InterfaceSlice(deployments.Items) | ||
} | ||
|
||
// GetDaemonSetItems returns the daemonSet in given namespace | ||
func GetDaemonSetItems(client kubernetes.Interface, namespace string) []interface{} { | ||
daemonSets, err := client.ExtensionsV1beta1().DaemonSets(namespace).List(meta_v1.ListOptions{}) | ||
if err != nil { | ||
logrus.Errorf("Failed to list daemonSets %v", err) | ||
} | ||
return util.InterfaceSlice(daemonSets.Items) | ||
} | ||
|
||
// GetStatefulSetItems returns the statefulSet in given namespace | ||
func GetStatefulSetItems(client kubernetes.Interface, namespace string) []interface{} { | ||
statefulSets, err := client.AppsV1beta1().StatefulSets(namespace).List(meta_v1.ListOptions{}) | ||
if err != nil { | ||
logrus.Errorf("Failed to list statefulSets %v", err) | ||
} | ||
return util.InterfaceSlice(statefulSets.Items) | ||
} | ||
|
||
// GetDeploymentContainers returns the containers of given deployment | ||
func GetDeploymentContainers(item interface{}) []v1.Container { | ||
return item.(v1beta1.Deployment).Spec.Template.Spec.Containers | ||
} | ||
|
||
// GetDaemonSetContainers returns the containers of given daemonset | ||
func GetDaemonSetContainers(item interface{}) []v1.Container { | ||
return item.(v1beta1.DaemonSet).Spec.Template.Spec.Containers | ||
} | ||
|
||
// GetStatefulsetContainers returns the containers of given statefulSet | ||
func GetStatefulsetContainers(item interface{}) []v1.Container { | ||
return item.(apps_v1beta1.StatefulSet).Spec.Template.Spec.Containers | ||
} | ||
|
||
// UpdateDeployment performs rolling upgrade on deployment | ||
func UpdateDeployment(client kubernetes.Interface, namespace string, resource interface{}) error { | ||
deployment := resource.(v1beta1.Deployment) | ||
_, err := client.ExtensionsV1beta1().Deployments(namespace).Update(&deployment) | ||
return err | ||
} | ||
|
||
// UpdateDaemonSet performs rolling upgrade on daemonSet | ||
func UpdateDaemonSet(client kubernetes.Interface, namespace string, resource interface{}) error { | ||
daemonSet := resource.(v1beta1.DaemonSet) | ||
_, err := client.ExtensionsV1beta1().DaemonSets(namespace).Update(&daemonSet) | ||
return err | ||
} | ||
|
||
// UpdateStatefulset performs rolling upgrade on statefulSet | ||
func UpdateStatefulset(client kubernetes.Interface, namespace string, resource interface{}) error { | ||
statefulSet := resource.(apps_v1beta1.StatefulSet) | ||
_, err := client.AppsV1beta1().StatefulSets(namespace).Update(&statefulSet) | ||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package constants | ||
|
||
const ( | ||
// ConfigmapUpdateOnChangeAnnotation is an annotation to detect changes in configmaps | ||
ConfigmapUpdateOnChangeAnnotation = "configmap.reloader.stakater.com/reload" | ||
// SecretUpdateOnChangeAnnotation is an annotation to detect changes in secrets | ||
SecretUpdateOnChangeAnnotation = "secret.reloader.stakater.com/reload" | ||
) |
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,10 @@ | ||
package constants | ||
|
||
const ( | ||
// ConfigmapEnvVarPostfix is a postfix for configmap envVar | ||
ConfigmapEnvVarPostfix = "_CONFIGMAP" | ||
// SecretEnvVarPostfix is a postfix for secret envVar | ||
SecretEnvVarPostfix = "_SECRET" | ||
// EnvVarPrefix is a Prefix for environment variable | ||
EnvVarPrefix = "STAKATER_" | ||
) |
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.