-
Notifications
You must be signed in to change notification settings - Fork 40.1k
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
StatefulSet kubectl rollout command #49674
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
apiVersion: apps/v1beta2 | ||
kind: StatefulSet | ||
metadata: | ||
name: nginx | ||
spec: | ||
selector: | ||
matchLabels: | ||
app: nginx-statefulset | ||
updateStrategy: | ||
type: RollingUpdate | ||
serviceName: "nginx" | ||
replicas: 0 | ||
template: | ||
metadata: | ||
labels: | ||
app: nginx-statefulset | ||
spec: | ||
terminationGracePeriodSeconds: 5 | ||
containers: | ||
- name: nginx | ||
image: gcr.io/google_containers/nginx-slim:0.8 | ||
ports: | ||
- containerPort: 80 | ||
name: web | ||
command: | ||
- sh | ||
- -c | ||
- 'while true; do sleep 1; done' | ||
- name: pause | ||
image: gcr.io/google-containers/pause:2.0 | ||
ports: | ||
- containerPort: 81 | ||
name: web-2 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,7 @@ var ( | |
|
||
* deployments | ||
* daemonsets | ||
* statefulsets | ||
`) | ||
) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -153,9 +153,9 @@ type DaemonSetHistoryViewer struct { | |
// ViewHistory returns a revision-to-history map as the revision history of a deployment | ||
// TODO: this should be a describer | ||
func (h *DaemonSetHistoryViewer) ViewHistory(namespace, name string, revision int64) (string, error) { | ||
versionedExtensionsClient := versionedExtensionsClientV1beta1(h.c) | ||
versionedAppsClient := versionedAppsClientV1beta1(h.c) | ||
ds, allHistory, err := controlledHistories(versionedExtensionsClient, versionedAppsClient, namespace, name) | ||
versionedExtensionsClient := versionedExtensionsClientV1beta1(h.c) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change isn't necessary (unless there's a reason to move it?) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I switched the order that puts There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. okay |
||
versionedObj, allHistory, err := controlledHistories(versionedAppsClient, versionedExtensionsClient, namespace, name, "DaemonSet") | ||
if err != nil { | ||
return "", fmt.Errorf("unable to find history controlled by DaemonSet %s: %v", name, err) | ||
} | ||
|
@@ -175,7 +175,13 @@ func (h *DaemonSetHistoryViewer) ViewHistory(namespace, name string, revision in | |
if !ok { | ||
return "", fmt.Errorf("unable to find the specified revision") | ||
} | ||
dsOfHistory, err := applyHistory(ds, history) | ||
|
||
versionedDS, ok := versionedObj.(*extensionsv1beta1.DaemonSet) | ||
if !ok { | ||
return "", fmt.Errorf("unexpected non-DaemonSet object returned: %v", versionedDS) | ||
} | ||
|
||
dsOfHistory, err := applyHistory(versionedDS, history) | ||
if err != nil { | ||
return "", fmt.Errorf("unable to parse history %s", history.Name) | ||
} | ||
|
@@ -256,29 +262,51 @@ func (h *StatefulSetHistoryViewer) ViewHistory(namespace, name string, revision | |
}) | ||
} | ||
|
||
// controlledHistories returns all ControllerRevisions controlled by the given DaemonSet | ||
func controlledHistories(extensions clientextensionsv1beta1.ExtensionsV1beta1Interface, apps clientappsv1beta1.AppsV1beta1Interface, namespace, name string) (*extensionsv1beta1.DaemonSet, []*appsv1beta1.ControllerRevision, error) { | ||
ds, err := extensions.DaemonSets(namespace).Get(name, metav1.GetOptions{}) | ||
if err != nil { | ||
return nil, nil, fmt.Errorf("failed to retrieve DaemonSet %s: %v", name, err) | ||
// controlledHistories returns all ControllerRevisions controlled by the given API object | ||
func controlledHistories(apps clientappsv1beta1.AppsV1beta1Interface, extensions clientextensionsv1beta1.ExtensionsV1beta1Interface, namespace, name, kind string) (runtime.Object, []*appsv1beta1.ControllerRevision, error) { | ||
var obj runtime.Object | ||
var labelSelector *metav1.LabelSelector | ||
|
||
switch kind { | ||
case "DaemonSet": | ||
ds, err := extensions.DaemonSets(namespace).Get(name, metav1.GetOptions{}) | ||
if err != nil { | ||
return nil, nil, fmt.Errorf("failed to retrieve DaemonSet %s: %v", name, err) | ||
} | ||
labelSelector = ds.Spec.Selector | ||
obj = ds | ||
case "StatefulSet": | ||
ss, err := apps.StatefulSets(namespace).Get(name, metav1.GetOptions{}) | ||
if err != nil { | ||
return nil, nil, fmt.Errorf("failed to retrieve StatefulSet %s: %v", name, err) | ||
} | ||
labelSelector = ss.Spec.Selector | ||
obj = ss | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add a default case and return error? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure! |
||
default: | ||
return nil, nil, fmt.Errorf("unsupported API object kind: %s", kind) | ||
} | ||
|
||
var result []*appsv1beta1.ControllerRevision | ||
selector, err := metav1.LabelSelectorAsSelector(ds.Spec.Selector) | ||
selector, err := metav1.LabelSelectorAsSelector(labelSelector) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
historyList, err := apps.ControllerRevisions(ds.Namespace).List(metav1.ListOptions{LabelSelector: selector.String()}) | ||
historyList, err := apps.ControllerRevisions(namespace).List(metav1.ListOptions{LabelSelector: selector.String()}) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
accessor, err := meta.Accessor(obj) | ||
if err != nil { | ||
return nil, nil, fmt.Errorf("failed to obtain accessor for %s named %s: %v", kind, name, err) | ||
} | ||
for i := range historyList.Items { | ||
history := historyList.Items[i] | ||
// Only add history that belongs to the DaemonSet | ||
if metav1.IsControlledBy(&history, ds) { | ||
// Only add history that belongs to the API object | ||
if metav1.IsControlledBy(&history, accessor) { | ||
result = append(result, &history) | ||
} | ||
} | ||
return ds, result, nil | ||
return obj, result, nil | ||
} | ||
|
||
// applyHistory returns a specific revision of DaemonSet by applying the given history to a copy of the given DaemonSet | ||
|
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.
@crimsonfaith91 looks like you need it in kubectl/rollback.go, so i don't see another way. perhaps someone else has an idea