Skip to content

Commit

Permalink
Do not include Config to MachineRegistration as pointer (#870)
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Mazzotti <[email protected]>
  • Loading branch information
anmazzotti committed Oct 17, 2024
1 parent afcdf10 commit d44f3f7
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 37 deletions.
10 changes: 2 additions & 8 deletions api/v1beta1/machineregistration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type MachineRegistrationSpec struct {
MachineInventoryAnnotations map[string]string `json:"machineInventoryAnnotations,omitempty"`
// Config the cloud config that will be used to provision the node.
// +optional
Config *Config `json:"config,omitempty"`
Config Config `json:"config,omitempty"`
}

type MachineRegistrationStatus struct {
Expand Down Expand Up @@ -80,13 +80,7 @@ type MachineRegistrationList struct {
// GetClientRegistrationConfig returns the configuration required by the elemental-register
// to register itself against this MachineRegistration instance.
func (m MachineRegistration) GetClientRegistrationConfig(cacert string) (*Config, error) {
conf := m.Spec.Config

if conf == nil {
conf = &Config{}
}

mRegistration := conf.Elemental.Registration
mRegistration := m.Spec.Config.Elemental.Registration

if !meta.IsStatusConditionTrue(m.Status.Conditions, ReadyCondition) {
return nil, fmt.Errorf("machine registration is not ready")
Expand Down
6 changes: 1 addition & 5 deletions api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions controllers/seedimage_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ var _ = Describe("reconcile seed image", func() {
},
},
Spec: elementalv1.MachineRegistrationSpec{
Config: &elementalv1.Config{
Config: elementalv1.Config{
Elemental: elementalv1.Elemental{
Install: elementalv1.Install{},
},
Expand Down Expand Up @@ -208,7 +208,7 @@ var _ = Describe("validate seed image", func() {
},
},
Spec: elementalv1.MachineRegistrationSpec{
Config: &elementalv1.Config{
Config: elementalv1.Config{
Elemental: elementalv1.Elemental{
Install: elementalv1.Install{},
},
Expand Down Expand Up @@ -302,7 +302,7 @@ var _ = Describe("reconcile seed image build container", func() {
},
},
Spec: elementalv1.MachineRegistrationSpec{
Config: &elementalv1.Config{
Config: elementalv1.Config{
Elemental: elementalv1.Elemental{
Install: elementalv1.Install{},
},
Expand Down Expand Up @@ -426,7 +426,7 @@ var _ = Describe("reconcileBuildImagePod", func() {
},
},
Spec: elementalv1.MachineRegistrationSpec{
Config: &elementalv1.Config{
Config: elementalv1.Config{
Elemental: elementalv1.Elemental{
Install: elementalv1.Install{},
},
Expand Down Expand Up @@ -623,7 +623,7 @@ var _ = Describe("createConfigMapObject", func() {
},
},
Spec: elementalv1.MachineRegistrationSpec{
Config: &elementalv1.Config{
Config: elementalv1.Config{
Elemental: elementalv1.Elemental{
Install: elementalv1.Install{},
},
Expand Down
4 changes: 0 additions & 4 deletions pkg/server/api_registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,6 @@ func (i *InventoryServer) writeMachineInventoryCloudConfig(conn *websocket.Conn,
return fmt.Errorf("server-url is not set")
}

if registration.Spec.Config == nil {
registration.Spec.Config = &elementalv1.Config{}
}

config, err := registration.GetClientRegistrationConfig(i.getRancherCACert())
if err != nil {
return err
Expand Down
9 changes: 5 additions & 4 deletions pkg/server/api_registration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"net/http"
"net/http/httptest"
"path"
"reflect"
"strings"
"testing"

Expand Down Expand Up @@ -52,15 +53,15 @@ import (

func TestUnauthenticatedResponse(t *testing.T) {
testCase := []struct {
config *elementalv1.Config
config elementalv1.Config
regUrl string
}{
{
config: nil,
config: elementalv1.Config{},
regUrl: "https://rancher/url1",
},
{
config: &elementalv1.Config{
config: elementalv1.Config{
Elemental: elementalv1.Elemental{
Registration: elementalv1.Registration{
EmulateTPM: true,
Expand Down Expand Up @@ -106,7 +107,7 @@ func TestUnauthenticatedResponse(t *testing.T) {

confReg := conf.Elemental.Registration
testReg := elementalv1.Registration{}
if test.config != nil {
if !reflect.DeepEqual(test.config, elementalv1.Config{}) {
testReg = test.config.Elemental.Registration
}
assert.Equal(t, confReg.EmulateTPM, testReg.EmulateTPM)
Expand Down
3 changes: 0 additions & 3 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,6 @@ func (i *InventoryServer) authMachine(conn *websocket.Conn, req *http.Request, r
func initInventory(inventory *elementalv1.MachineInventory, registration *elementalv1.MachineRegistration) {
const namePrefix = "m-"

if registration.Spec.Config == nil {
registration.Spec.Config = &elementalv1.Config{}
}
inventory.Name = registration.Spec.MachineName
if inventory.Name == "" {
inventory.Name = namePrefix + uuid.NewString()
Expand Down
10 changes: 5 additions & 5 deletions pkg/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ func TestInitNewInventory(t *testing.T) {
// e.g., m-66588488-3eb6-4a6d-b642-c994f128c6f1

testCase := []struct {
config *elementalv1.Config
config elementalv1.Config
initName string
expectedName string
}{
{
config: &elementalv1.Config{
config: elementalv1.Config{
Elemental: elementalv1.Elemental{
Registration: elementalv1.Registration{
NoSMBIOS: false,
Expand All @@ -48,7 +48,7 @@ func TestInitNewInventory(t *testing.T) {
},

{
config: &elementalv1.Config{
config: elementalv1.Config{
Elemental: elementalv1.Elemental{
Registration: elementalv1.Registration{
NoSMBIOS: false,
Expand All @@ -57,7 +57,7 @@ func TestInitNewInventory(t *testing.T) {
},
},
{
config: &elementalv1.Config{
config: elementalv1.Config{
Elemental: elementalv1.Elemental{
Registration: elementalv1.Registration{
NoSMBIOS: true,
Expand All @@ -66,7 +66,7 @@ func TestInitNewInventory(t *testing.T) {
},
},
{
config: nil,
config: elementalv1.Config{},
},
}

Expand Down
2 changes: 1 addition & 1 deletion tests/catalog/manageregistration.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func NewMachineRegistration(namespace string, name string, config *elementalv1.Config) *elementalv1.MachineRegistration {
func NewMachineRegistration(namespace string, name string, config elementalv1.Config) *elementalv1.MachineRegistration {
return &elementalv1.MachineRegistration{
TypeMeta: metav1.TypeMeta{
APIVersion: "elemental.cattle.io/v1beta1",
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/machineregistration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var _ = Describe("MachineRegistration e2e tests", func() {
mRegistration = catalog.NewMachineRegistration(
fleetNamespace,
"machine-registration",
&elementalv1.Config{})
elementalv1.Config{})
})

AfterEach(func() {
Expand Down Expand Up @@ -77,7 +77,7 @@ var _ = Describe("MachineRegistration e2e tests", func() {
mRegistration = catalog.NewMachineRegistration(
fleetNamespace,
"machine-registration",
&elementalv1.Config{
elementalv1.Config{
Elemental: elementalv1.Elemental{
Install: elementalv1.Install{
Device: "/dev/vda",
Expand Down

0 comments on commit d44f3f7

Please sign in to comment.