@@ -19,21 +19,14 @@ package alpha
19
19
import (
20
20
"context"
21
21
"fmt"
22
- "strconv"
23
22
"time"
24
23
25
24
"github.com/pkg/errors"
26
- "k8s.io/apimachinery/pkg/api/meta"
27
- metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
28
- "k8s.io/apimachinery/pkg/labels"
29
- "k8s.io/apimachinery/pkg/runtime"
30
25
"k8s.io/apimachinery/pkg/types"
31
- "k8s.io/klog/v2"
32
26
"sigs.k8s.io/controller-runtime/pkg/client"
33
27
34
28
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
35
29
"sigs.k8s.io/cluster-api/cmd/clusterctl/client/cluster"
36
- logf "sigs.k8s.io/cluster-api/cmd/clusterctl/log"
37
30
)
38
31
39
32
// getMachineDeployment retrieves the MachineDeployment object corresponding to the name and namespace specified.
@@ -80,99 +73,3 @@ func patchMachineDeployment(ctx context.Context, proxy cluster.Proxy, name, name
80
73
}
81
74
return nil
82
75
}
83
-
84
- // findMachineDeploymentRevision finds the specific revision in the machine sets.
85
- func findMachineDeploymentRevision (toRevision int64 , allMSs []* clusterv1.MachineSet ) (* clusterv1.MachineSet , error ) {
86
- var (
87
- latestMachineSet * clusterv1.MachineSet
88
- latestRevision = int64 (- 1 )
89
- previousMachineSet * clusterv1.MachineSet
90
- previousRevision = int64 (- 1 )
91
- )
92
- for _ , ms := range allMSs {
93
- if v , err := revision (ms ); err == nil {
94
- switch toRevision {
95
- case 0 :
96
- if latestRevision < v {
97
- // newest one we've seen so far
98
- previousRevision = latestRevision
99
- previousMachineSet = latestMachineSet
100
- latestRevision = v
101
- latestMachineSet = ms
102
- } else if previousRevision < v {
103
- // second newest one we've seen so far
104
- previousRevision = v
105
- previousMachineSet = ms
106
- }
107
- case v :
108
- return ms , nil
109
- }
110
- }
111
- }
112
-
113
- if toRevision > 0 {
114
- return nil , errors .Errorf ("unable to find specified MachineDeployment revision: %v" , toRevision )
115
- }
116
-
117
- if previousMachineSet == nil {
118
- return nil , errors .Errorf ("no rollout history found for MachineDeployment" )
119
- }
120
- return previousMachineSet , nil
121
- }
122
-
123
- // getMachineSetsForDeployment returns a list of MachineSets associated with a MachineDeployment.
124
- func getMachineSetsForDeployment (ctx context.Context , proxy cluster.Proxy , md * clusterv1.MachineDeployment ) ([]* clusterv1.MachineSet , error ) {
125
- log := logf .Log
126
- c , err := proxy .NewClient (ctx )
127
- if err != nil {
128
- return nil , err
129
- }
130
- // List all MachineSets to find those we own but that no longer match our selector.
131
- machineSets := & clusterv1.MachineSetList {}
132
- if err := c .List (ctx , machineSets , client .InNamespace (md .Namespace )); err != nil {
133
- return nil , err
134
- }
135
-
136
- filtered := make ([]* clusterv1.MachineSet , 0 , len (machineSets .Items ))
137
- for idx := range machineSets .Items {
138
- ms := & machineSets .Items [idx ]
139
- log := log .WithValues ("MachineSet" , klog .KObj (ms ))
140
-
141
- // Skip this MachineSet if its controller ref is not pointing to this MachineDeployment
142
- if ! metav1 .IsControlledBy (ms , md ) {
143
- log .V (5 ).Info ("Skipping MachineSet, controller ref does not match MachineDeployment" )
144
- continue
145
- }
146
-
147
- selector , err := metav1 .LabelSelectorAsSelector (& md .Spec .Selector )
148
- if err != nil {
149
- log .V (5 ).Info ("Skipping MachineSet, failed to get label selector from spec selector" )
150
- continue
151
- }
152
- // If a MachineDeployment with a nil or empty selector creeps in, it should match nothing, not everything.
153
- if selector .Empty () {
154
- log .V (5 ).Info ("Skipping MachineSet as the selector is empty" )
155
- continue
156
- }
157
- // Skip this MachineSet if selector does not match
158
- if ! selector .Matches (labels .Set (ms .Labels )) {
159
- log .V (5 ).Info ("Skipping MachineSet, label mismatch" )
160
- continue
161
- }
162
- filtered = append (filtered , ms )
163
- }
164
-
165
- return filtered , nil
166
- }
167
-
168
- func revision (obj runtime.Object ) (int64 , error ) {
169
- acc , err := meta .Accessor (obj )
170
- if err != nil {
171
- return 0 , err
172
- }
173
- v , ok := acc .GetAnnotations ()[clusterv1 .RevisionAnnotation ]
174
- if ! ok {
175
- return 0 , nil
176
- }
177
- return strconv .ParseInt (v , 10 , 64 )
178
- }
0 commit comments