Skip to content

Commit

Permalink
Merge branch 'main' into minor
Browse files Browse the repository at this point in the history
  • Loading branch information
kkaempf authored Aug 8, 2024
2 parents b17f4c8 + 36468ab commit 302dd56
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 32 deletions.
5 changes: 0 additions & 5 deletions cmd/register/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,6 @@ func newCommand(fs vfs.FS, client register.Client, stateHandler register.StateHa
if err != nil {
return fmt.Errorf("getting registration state: %w", err)
}
// Determine if registration should execute or skip a cycle
if !installation && !reset && !registrationState.HasLastUpdateElapsed(registrationUpdateSuppressTimer) {
log.Info("Nothing to do")
return nil
}
// Validate CA
caCert, err := getRegistrationCA(fs, cfg)
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions cmd/register/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ var (
}
stateFixture = register.State{
InitialRegistration: time.Now(),
LastUpdate: time.Time{},
EmulatedTPM: true,
EmulatedTPMSeed: 987654321,
}
Expand Down Expand Up @@ -206,18 +205,19 @@ var _ = Describe("elemental-register state", Label("registration", "cli", "state
cmd.SetArgs([]string{"--state-path", newPath})
registrationState := register.State{
InitialRegistration: time.Now(),
LastUpdate: time.Now(),
}
stateHandler.EXPECT().Init(newPath).Return(nil)
stateHandler.EXPECT().Load().Return(registrationState, nil)
client.EXPECT().Register(gomock.Any(), gomock.Any(), gomock.Any()).Times(0)
stateHandler.EXPECT().Save(registrationState).Return(nil)
client.EXPECT().
Register(baseConfigFixture.Elemental.Registration, []byte(baseConfigFixture.Elemental.Registration.CACert), &registrationState).
Return(marshalToBytes(baseConfigFixture), nil)
Expect(cmd.Execute()).ToNot(HaveOccurred())
})
It("should not skip registration if lastUpdate is stale", func() {
It("should return the registration data", func() {
cmd.SetArgs([]string{})
registrationState := register.State{
InitialRegistration: time.Now(),
LastUpdate: time.Now().Add(-25 * time.Hour),
}
stateHandler.EXPECT().Init(defaultStatePath).Return(nil)
stateHandler.EXPECT().Load().Return(registrationState, nil)
Expand Down
1 change: 0 additions & 1 deletion pkg/install/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ var (
}
stateFixture = register.State{
InitialRegistration: time.Date(2023, time.August, 2, 12, 35, 10, 3, time.UTC),
LastUpdate: time.Time{},
EmulatedTPM: true,
EmulatedTPMSeed: 987654321,
}
Expand Down
1 change: 0 additions & 1 deletion pkg/register/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ func (r *client) Register(reg elementalv1.Registration, caCert []byte, state *St
if err := sendUpdateData(conn); err != nil {
return nil, fmt.Errorf("failed to send update data: %w", err)
}
state.LastUpdate = time.Now()
} else {
state.InitialRegistration = time.Now()
}
Expand Down
5 changes: 0 additions & 5 deletions pkg/register/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (

type State struct {
InitialRegistration time.Time `yaml:"initialRegistration,omitempty"`
LastUpdate time.Time `yaml:"lastUpdate,omitempty"`
EmulatedTPM bool `yaml:"emulatedTPM,omitempty"`
EmulatedTPMSeed int64 `yaml:"emulatedTPMSeed,omitempty"`
}
Expand All @@ -40,10 +39,6 @@ func (s *State) IsUpdatable() bool {
return !s.InitialRegistration.IsZero()
}

func (s *State) HasLastUpdateElapsed(suppress time.Duration) bool {
return time.Now().After(s.LastUpdate.Add(suppress))
}

type StateHandler interface {
Init(location string) error
Load() (State, error)
Expand Down
15 changes: 0 additions & 15 deletions pkg/register/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@ func TestRegister(t *testing.T) {
var (
testStateDir = "/test/register/state"
testStatePath = fmt.Sprintf("%s/%s", testStateDir, "state.yaml")
loc, _ = time.LoadLocation("Europe/Berlin")
stateFixture = State{
InitialRegistration: time.Now().UTC(),
LastUpdate: time.Now().UTC(),
EmulatedTPM: true,
EmulatedTPMSeed: 123456789,
}
Expand All @@ -59,19 +57,6 @@ var _ = Describe("is state updatable", Label("registration", "state"), func() {
})
})

var _ = Describe("has state update elapsed", Label("registration", "state"), func() {
It("returns false if the state is new", func() {
state := State{}
Expect(state.HasLastUpdateElapsed(-1 * time.Hour)).To(BeTrue())
})
It("returns true last update time is more than suppress timer ago", func() {
state := State{
LastUpdate: time.Now().Add(-10 * time.Hour),
}
Expect(state.HasLastUpdateElapsed(1 * time.Hour)).To(BeTrue())
})
})

var _ = Describe("init file state handler", Label("registration", "state"), func() {
var fs vfs.FS
var handler StateHandler
Expand Down

0 comments on commit 302dd56

Please sign in to comment.