Skip to content
This repository was archived by the owner on Jan 9, 2023. It is now read-only.

Commit 73a40e3

Browse files
committed
Improve responsiveness and display machine id of converging
Signed-off-by: JoshVanL <vleeuwenjoshua@gmail.com>
1 parent e1ed61e commit 73a40e3

12 files changed

Lines changed: 74 additions & 66 deletions

File tree

pkg/apis/wing/machine_types.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package wing
33

44
import (
55
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
6+
7+
"github.com/jetstack/tarmak/pkg/apis/wing/common"
68
)
79

810
// +genclient
@@ -36,9 +38,8 @@ type MachineStatus struct {
3638
}
3739

3840
// InstaceSpecManifest defines the state and hash of a run manifest
39-
type MachineManifestState string
4041
type MachineStatusManifest struct {
41-
State MachineManifestState
42+
State common.MachineManifestState
4243
Hash string
4344
LastUpdateTimestamp metav1.Time
4445
Messages []string

pkg/apis/wing/v1alpha1/constants.go

Lines changed: 0 additions & 10 deletions
This file was deleted.

pkg/apis/wing/v1alpha1/machine_types.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package v1alpha1
33

44
import (
55
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
6+
7+
"github.com/jetstack/tarmak/pkg/apis/wing/common"
68
)
79

810
// +genclient
@@ -37,11 +39,11 @@ type MachineStatus struct {
3739

3840
// InstaceSpecManifest defines the state and hash of a run manifest
3941
type MachineStatusManifest struct {
40-
State MachineManifestState `json:"state,omitempty"`
41-
Hash string `json:"hash,omitempty"` // hash of manifests, prefixed with type (eg: sha256:xyz)
42-
LastUpdateTimestamp metav1.Time `json:"lastUpdateTimestamp,omitempty"` // timestamp when a converge was requested
43-
Messages []string `json:"messages,omitempty"` // contains output of the retries
44-
ExitCodes []int `json:"exitCodes,omitempty"` // return code of the retries
42+
State common.MachineManifestState `json:"state,omitempty"`
43+
Hash string `json:"hash,omitempty"` // hash of manifests, prefixed with type (eg: sha256:xyz)
44+
LastUpdateTimestamp metav1.Time `json:"lastUpdateTimestamp,omitempty"` // timestamp when a converge was requested
45+
Messages []string `json:"messages,omitempty"` // contains output of the retries
46+
ExitCodes []int `json:"exitCodes,omitempty"` // return code of the retries
4547
}
4648

4749
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

pkg/apis/wing/v1alpha1/zz_generated.conversion.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ func Convert_wing_MachineStatus_To_v1alpha1_MachineStatus(in *wing.MachineStatus
445445
}
446446

447447
func autoConvert_v1alpha1_MachineStatusManifest_To_wing_MachineStatusManifest(in *MachineStatusManifest, out *wing.MachineStatusManifest, s conversion.Scope) error {
448-
out.State = wing.MachineManifestState(in.State)
448+
out.State = common.MachineManifestState(in.State)
449449
out.Hash = in.Hash
450450
out.LastUpdateTimestamp = in.LastUpdateTimestamp
451451
out.Messages = *(*[]string)(unsafe.Pointer(&in.Messages))
@@ -459,7 +459,7 @@ func Convert_v1alpha1_MachineStatusManifest_To_wing_MachineStatusManifest(in *Ma
459459
}
460460

461461
func autoConvert_wing_MachineStatusManifest_To_v1alpha1_MachineStatusManifest(in *wing.MachineStatusManifest, out *MachineStatusManifest, s conversion.Scope) error {
462-
out.State = MachineManifestState(in.State)
462+
out.State = common.MachineManifestState(in.State)
463463
out.Hash = in.Hash
464464
out.LastUpdateTimestamp = in.LastUpdateTimestamp
465465
out.Messages = *(*[]string)(unsafe.Pointer(&in.Messages))

pkg/tarmak/cluster/configuration.go

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"strings"
1010
"time"
1111

12+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
13+
1214
wingv1alpha1 "github.com/jetstack/tarmak/pkg/apis/wing/v1alpha1"
1315
)
1416

@@ -64,10 +66,8 @@ func (c *Cluster) ReapplyConfiguration() error {
6466

6567
for pos, _ := range machines {
6668
machine := machines[pos]
67-
if machine.Spec == nil {
68-
machine.Spec = &wingv1alpha1.MachineSpec{}
69-
}
70-
machine.Spec.Converge = &wingv1alpha1.MachineSpecManifest{}
69+
machine.Status = &wingv1alpha1.MachineStatus{}
70+
machine.Status.Converge = &wingv1alpha1.MachineStatusManifest{}
7171

7272
if _, err := client.Update(machine); err != nil {
7373
c.log.Warnf("error updating machine %s in wing API: %s", machine.Name, err)
@@ -128,13 +128,33 @@ func (c *Cluster) WaitForConvergance() error {
128128
c.log.Debug(convergedStr)
129129
}
130130

131+
client, err := c.wingMachineClient()
132+
if err != nil {
133+
return err
134+
}
135+
131136
for _, d := range converging {
137+
138+
mList, err := client.List(metav1.ListOptions{
139+
LabelSelector: fmt.Sprintf("pool=%s,cluster=%s",
140+
d.Labels["pool"], d.Labels["cluster"]),
141+
})
142+
if err != nil {
143+
return err
144+
}
145+
146+
var convergingMachines []string
147+
for _, m := range mList.Items {
148+
convergingMachines = append(convergingMachines, m.Name)
149+
}
150+
132151
reps := d.Status.Replicas
133152
if d.Spec != nil && d.Spec.MinReplicas != nil && reps < *d.Spec.MinReplicas {
134153
reps = *d.Spec.MinReplicas
135154
}
136155

137-
c.log.Debugf("converging %s [%v/%v]", d.Name, d.Status.ReadyReplicas, reps)
156+
c.log.Debugf("converging %s [%v/%v] (%s)",
157+
d.Name, d.Status.ReadyReplicas, reps, strings.Join(convergingMachines, ", "))
138158
}
139159

140160
retries--

pkg/tarmak/cluster/wing.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
apierrors "k8s.io/apimachinery/pkg/api/errors"
1111
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1212

13+
"github.com/jetstack/tarmak/pkg/apis/wing/common"
1314
wingv1alpha1 "github.com/jetstack/tarmak/pkg/apis/wing/v1alpha1"
1415
"github.com/jetstack/tarmak/pkg/tarmak/interfaces"
1516
"github.com/jetstack/tarmak/pkg/tarmak/utils"
@@ -60,7 +61,7 @@ func (c *Cluster) listMachines() ([]*wingv1alpha1.Machine, error) {
6061
},
6162
Status: &wingv1alpha1.MachineStatus{
6263
Converge: &wingv1alpha1.MachineStatusManifest{
63-
State: wingv1alpha1.MachineManifestStateConverging,
64+
State: common.MachineManifestStateConverging,
6465
},
6566
},
6667
}
@@ -131,9 +132,7 @@ func (c *Cluster) updateMachineDeployments() error {
131132
continue
132133
}
133134

134-
d = d.DeepCopy()
135135
d.Spec = c.deploymentSpec(i)
136-
137136
_, err = client.Update(d)
138137
if err != nil {
139138
return fmt.Errorf("failed to update deployment sepc %s: %s", i.Name(), err)

pkg/wing/controller/machine/controller.go

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"k8s.io/client-go/tools/cache"
1414
"k8s.io/client-go/util/workqueue"
1515

16+
"github.com/jetstack/tarmak/pkg/apis/wing/common"
1617
"github.com/jetstack/tarmak/pkg/apis/wing/v1alpha1"
1718
"github.com/jetstack/tarmak/pkg/wing/interfaces"
1819
)
@@ -81,7 +82,7 @@ func (c *Controller) syncToStdout(key string) error {
8182
},
8283
Status: &v1alpha1.MachineStatus{
8384
Converge: &v1alpha1.MachineStatusManifest{
84-
State: v1alpha1.MachineManifestStateConverging,
85+
State: common.MachineManifestStateConverging,
8586
},
8687
},
8788
}
@@ -91,33 +92,36 @@ func (c *Controller) syncToStdout(key string) error {
9192
}
9293

9394
c.log.Infof("Machine created %v", key)
94-
} else {
95-
// Note that you also have to check the uid if you have a local controlled resource, which
96-
// is dependent on the actual machine, to detect that a Machine was recreated with the same name
97-
machine, ok := obj.(*v1alpha1.Machine)
98-
if !ok {
99-
return errors.New("failed to process next item, not a machine")
100-
}
95+
return nil
96+
}
97+
98+
// Note that you also have to check the uid if you have a local controlled resource, which
99+
// is dependent on the actual machine, to detect that a Machine was recreated with the same name
100+
machine, ok := obj.(*v1alpha1.Machine)
101+
if !ok {
102+
return errors.New("failed to process next item, not a machine")
103+
}
101104

102-
// trigger converge if status time is older or not existing
103-
if machine.Spec != nil && machine.Spec.Converge != nil && !machine.Spec.Converge.RequestTimestamp.Time.IsZero() {
104-
if machine.Status != nil && machine.Status.Converge != nil && !machine.Status.Converge.LastUpdateTimestamp.Time.IsZero() {
105-
if machine.Status.Converge.LastUpdateTimestamp.Time.After(machine.Spec.Converge.RequestTimestamp.Time) {
106-
c.log.Debug("no converge neccessary, last update was after request")
107-
return nil
108-
}
109-
} else {
110-
c.log.Debug("no converge neccessary, no status section found or update timestamp zero")
105+
// trigger converge if status time is older or not existing
106+
if machine.Spec != nil && machine.Spec.Converge != nil && !machine.Spec.Converge.RequestTimestamp.Time.IsZero() {
107+
if machine.Status != nil && machine.Status.Converge != nil && !machine.Status.Converge.LastUpdateTimestamp.Time.IsZero() {
108+
if machine.Status.Converge.LastUpdateTimestamp.Time.After(machine.Spec.Converge.RequestTimestamp.Time) {
109+
c.log.Debug("no converge neccessary, last update was after request")
111110
return nil
112111
}
113112
} else {
114-
c.log.Debug("no converge neccessary, no spec section found or request timestamp zero")
113+
c.log.Debug("no converge neccessary, no status section found or update timestamp zero")
115114
return nil
116115
}
116+
}
117117

118+
if machine.Status != nil && machine.Status.Converge != nil &&
119+
machine.Status.Converge.State != common.MachineManifestStateConverging &&
120+
machine.Status.Converge.State != common.MachineManifestStateConverged {
118121
c.log.Infof("running converge")
119122
c.wing.Converge()
120123
}
124+
121125
return nil
122126
}
123127

pkg/wing/controller/machinedeployment/controller.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ func (c *Controller) sync(key string) error {
7272
return err
7373
}
7474

75-
c.log.Debugf("machine deployment controller did not get deployment or set")
76-
7775
if !exists {
7876
return nil
7977
}
@@ -83,16 +81,12 @@ func (c *Controller) sync(key string) error {
8381
return errors.New("failed to process next item, not a machinedeployment or machineset")
8482
}
8583

86-
c.log.Debugf("machine deployment controller got machineset: %s", ms.Name)
87-
8884
// get our deployment controlling this set
8985
md, err := c.getMachineDeployment(ms)
9086
if err != nil {
9187
return err
9288
}
9389

94-
c.log.Debugf("machine deployment controller got matching matchine deployment: %s", md.Name)
95-
9690
// sync deployment from the set
9791
return c.syncFromMachineSet(md, ms)
9892
}

pkg/wing/controller/machineset/controller.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"k8s.io/client-go/tools/cache"
1616
"k8s.io/client-go/util/workqueue"
1717

18+
"github.com/jetstack/tarmak/pkg/apis/wing/common"
1819
"github.com/jetstack/tarmak/pkg/apis/wing/v1alpha1"
1920
clientset "github.com/jetstack/tarmak/pkg/wing/client/clientset/versioned"
2021
)
@@ -72,8 +73,6 @@ func (c *Controller) syncToStdout(key string) error {
7273
return errors.New("failed to process next item, not a machine")
7374
}
7475

75-
c.log.Debugf("machineset controller got a mahcine: %s", m.Name)
76-
7776
ms, found, err := c.getMachineSet(m)
7877
if err != nil {
7978
return err
@@ -85,8 +84,6 @@ func (c *Controller) syncToStdout(key string) error {
8584
return nil
8685
}
8786

88-
c.log.Debugf("machineset controller got matching machineset: %s", ms.Name)
89-
9087
if ms.Spec == nil {
9188
return fmt.Errorf("machineset spec is nil: %v", ms.Spec)
9289
}
@@ -235,7 +232,7 @@ func (c *Controller) runWorker() {
235232
}
236233

237234
func (c *Controller) machineConverged(machine v1alpha1.Machine) bool {
238-
if machine.Status != nil && machine.Status.Converge != nil && machine.Status.Converge.State == v1alpha1.MachineManifestStateConverged {
235+
if machine.Status != nil && machine.Status.Converge != nil && machine.Status.Converge.State == common.MachineManifestStateConverged {
239236
return true
240237
}
241238

pkg/wing/puppet.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
apierrors "k8s.io/apimachinery/pkg/api/errors"
2323
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2424

25+
"github.com/jetstack/tarmak/pkg/apis/wing/common"
2526
"github.com/jetstack/tarmak/pkg/apis/wing/v1alpha1"
2627
"github.com/jetstack/tarmak/pkg/wing/provider"
2728
)
@@ -31,7 +32,7 @@ func (w *Wing) runPuppet() (*v1alpha1.MachineStatus, error) {
3132
// start converging mainfest
3233
status := &v1alpha1.MachineStatus{
3334
Converge: &v1alpha1.MachineStatusManifest{
34-
State: v1alpha1.MachineManifestStateConverging,
35+
State: common.MachineManifestStateConverging,
3536
},
3637
}
3738

@@ -105,7 +106,7 @@ func (w *Wing) runPuppet() (*v1alpha1.MachineStatus, error) {
105106
// start converging mainfest
106107
status = &v1alpha1.MachineStatus{
107108
Converge: &v1alpha1.MachineStatusManifest{
108-
State: v1alpha1.MachineManifestStateConverging,
109+
State: common.MachineManifestStateConverging,
109110
Messages: puppetMessages,
110111
ExitCodes: puppetRetCodes,
111112
Hash: hashString,
@@ -159,11 +160,11 @@ func (w *Wing) Converge() {
159160
// run puppet
160161
status, err := w.runPuppet()
161162
if err != nil {
162-
status.Converge.State = v1alpha1.MachineManifestStateError
163+
status.Converge.State = common.MachineManifestStateError
163164
status.Converge.Messages = append(status.Converge.Messages, err.Error())
164165
w.log.Error(err)
165166
} else {
166-
status.Converge.State = v1alpha1.MachineManifestStateConverged
167+
status.Converge.State = common.MachineManifestStateConverged
167168
}
168169

169170
// feedback puppet status to apiserver

0 commit comments

Comments
 (0)