Skip to content
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

Revert: Deprecate SSHKeys in favor of SSHKeysRef variable #976

Merged
merged 1 commit into from
Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 4 additions & 61 deletions api/v1alpha3/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (

capiv1alpha3 "sigs.k8s.io/cluster-api/api/v1alpha3"
capiv1beta1 "sigs.k8s.io/cluster-api/api/v1beta1"
utilconversion "sigs.k8s.io/cluster-api/util/conversion"

infrav1beta1 "sigs.k8s.io/cluster-api-provider-ibmcloud/api/v1beta1"
)
Expand Down Expand Up @@ -63,41 +62,13 @@ func (dst *IBMVPCClusterList) ConvertFrom(srcRaw conversion.Hub) error {
func (src *IBMVPCMachine) ConvertTo(dstRaw conversion.Hub) error {
dst := dstRaw.(*infrav1beta1.IBMVPCMachine)

if err := Convert_v1alpha3_IBMVPCMachine_To_v1beta1_IBMVPCMachine(src, dst, nil); err != nil {
return err
}

for _, sshKey := range src.Spec.SSHKeys {
dst.Spec.SSHKeysRef = append(dst.Spec.SSHKeysRef, &infrav1beta1.IBMVPCResourceReference{
ID: sshKey,
})
}

return nil
return Convert_v1alpha3_IBMVPCMachine_To_v1beta1_IBMVPCMachine(src, dst, nil)
}

func (dst *IBMVPCMachine) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*infrav1beta1.IBMVPCMachine)

if err := Convert_v1beta1_IBMVPCMachine_To_v1alpha3_IBMVPCMachine(src, dst, nil); err != nil {
return err
}

// Preserve Hub data on down-conversion except for metadata
if err := utilconversion.MarshalData(src, dst); err != nil {
return err
}

if src.Spec.SSHKeysRef != nil {
for _, sshKey := range src.Spec.SSHKeysRef {
if sshKey.ID != nil {
// Only source keys with ID will be converted
dst.Spec.SSHKeys = append(dst.Spec.SSHKeys, sshKey.ID)
}
}
}

return nil
return Convert_v1beta1_IBMVPCMachine_To_v1alpha3_IBMVPCMachine(src, dst, nil)
}

func (src *IBMVPCMachineList) ConvertTo(dstRaw conversion.Hub) error {
Expand All @@ -115,41 +86,13 @@ func (dst *IBMVPCMachineList) ConvertFrom(srcRaw conversion.Hub) error {
func (src *IBMVPCMachineTemplate) ConvertTo(dstRaw conversion.Hub) error {
dst := dstRaw.(*infrav1beta1.IBMVPCMachineTemplate)

if err := Convert_v1alpha3_IBMVPCMachineTemplate_To_v1beta1_IBMVPCMachineTemplate(src, dst, nil); err != nil {
return err
}

for _, sshKey := range src.Spec.Template.Spec.SSHKeys {
dst.Spec.Template.Spec.SSHKeysRef = append(dst.Spec.Template.Spec.SSHKeysRef, &infrav1beta1.IBMVPCResourceReference{
ID: sshKey,
})
}

return nil
return Convert_v1alpha3_IBMVPCMachineTemplate_To_v1beta1_IBMVPCMachineTemplate(src, dst, nil)
}

func (dst *IBMVPCMachineTemplate) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*infrav1beta1.IBMVPCMachineTemplate)

if err := Convert_v1beta1_IBMVPCMachineTemplate_To_v1alpha3_IBMVPCMachineTemplate(src, dst, nil); err != nil {
return err
}

// Preserve Hub data on down-conversion except for metadata
if err := utilconversion.MarshalData(src, dst); err != nil {
return err
}

if src.Spec.Template.Spec.SSHKeysRef != nil {
for _, sshKey := range src.Spec.Template.Spec.SSHKeysRef {
if sshKey.ID != nil {
// Only source keys with ID will be converted
dst.Spec.Template.Spec.SSHKeys = append(dst.Spec.Template.Spec.SSHKeys, sshKey.ID)
}
}
}

return nil
return Convert_v1beta1_IBMVPCMachineTemplate_To_v1alpha3_IBMVPCMachineTemplate(src, dst, nil)
}

func (src *IBMVPCMachineTemplateList) ConvertTo(dstRaw conversion.Hub) error {
Expand Down
1 change: 0 additions & 1 deletion api/v1alpha3/zz_generated.conversion.go

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

66 changes: 4 additions & 62 deletions api/v1alpha4/ibmvpc_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import (

"sigs.k8s.io/controller-runtime/pkg/conversion"

utilconversion "sigs.k8s.io/cluster-api/util/conversion"

infrav1beta1 "sigs.k8s.io/cluster-api-provider-ibmcloud/api/v1beta1"
)

Expand Down Expand Up @@ -53,41 +51,13 @@ func (dst *IBMVPCClusterList) ConvertFrom(srcRaw conversion.Hub) error {
func (src *IBMVPCMachine) ConvertTo(dstRaw conversion.Hub) error {
dst := dstRaw.(*infrav1beta1.IBMVPCMachine)

if err := Convert_v1alpha4_IBMVPCMachine_To_v1beta1_IBMVPCMachine(src, dst, nil); err != nil {
return err
}

for _, sshKey := range src.Spec.SSHKeys {
dst.Spec.SSHKeysRef = append(dst.Spec.SSHKeysRef, &infrav1beta1.IBMVPCResourceReference{
ID: sshKey,
})
}

return nil
return Convert_v1alpha4_IBMVPCMachine_To_v1beta1_IBMVPCMachine(src, dst, nil)
}

func (dst *IBMVPCMachine) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*infrav1beta1.IBMVPCMachine)

if err := Convert_v1beta1_IBMVPCMachine_To_v1alpha4_IBMVPCMachine(src, dst, nil); err != nil {
return err
}

// Preserve Hub data on down-conversion except for metadata
if err := utilconversion.MarshalData(src, dst); err != nil {
return err
}

if src.Spec.SSHKeysRef != nil {
for _, sshKey := range src.Spec.SSHKeysRef {
if sshKey.ID != nil {
// Only source keys with ID will be converted
dst.Spec.SSHKeys = append(dst.Spec.SSHKeys, sshKey.ID)
}
}
}

return nil
return Convert_v1beta1_IBMVPCMachine_To_v1alpha4_IBMVPCMachine(src, dst, nil)
}

func (src *IBMVPCMachineList) ConvertTo(dstRaw conversion.Hub) error {
Expand All @@ -105,41 +75,13 @@ func (dst *IBMVPCMachineList) ConvertFrom(srcRaw conversion.Hub) error {
func (src *IBMVPCMachineTemplate) ConvertTo(dstRaw conversion.Hub) error {
dst := dstRaw.(*infrav1beta1.IBMVPCMachineTemplate)

if err := Convert_v1alpha4_IBMVPCMachineTemplate_To_v1beta1_IBMVPCMachineTemplate(src, dst, nil); err != nil {
return err
}

for _, sshKey := range src.Spec.Template.Spec.SSHKeys {
dst.Spec.Template.Spec.SSHKeysRef = append(dst.Spec.Template.Spec.SSHKeysRef, &infrav1beta1.IBMVPCResourceReference{
ID: sshKey,
})
}

return nil
return Convert_v1alpha4_IBMVPCMachineTemplate_To_v1beta1_IBMVPCMachineTemplate(src, dst, nil)
}

func (dst *IBMVPCMachineTemplate) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*infrav1beta1.IBMVPCMachineTemplate)

if err := Convert_v1beta1_IBMVPCMachineTemplate_To_v1alpha4_IBMVPCMachineTemplate(src, dst, nil); err != nil {
return err
}

// Preserve Hub data on down-conversion except for metadata
if err := utilconversion.MarshalData(src, dst); err != nil {
return err
}

if src.Spec.Template.Spec.SSHKeysRef != nil {
for _, sshKey := range src.Spec.Template.Spec.SSHKeysRef {
if sshKey.ID != nil {
// Only source keys with ID will be converted
dst.Spec.Template.Spec.SSHKeys = append(dst.Spec.Template.Spec.SSHKeys, sshKey.ID)
}
}
}

return nil
return Convert_v1beta1_IBMVPCMachineTemplate_To_v1alpha4_IBMVPCMachineTemplate(src, dst, nil)
}

func (src *IBMVPCMachineTemplateList) ConvertTo(dstRaw conversion.Hub) error {
Expand Down
1 change: 0 additions & 1 deletion api/v1alpha4/zz_generated.conversion.go

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

21 changes: 0 additions & 21 deletions api/v1beta1/ibmvpcmachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,28 +58,7 @@ type IBMVPCMachineSpec struct {
PrimaryNetworkInterface NetworkInterface `json:"primaryNetworkInterface,omitempty"`

// SSHKeys is the SSH pub keys that will be used to access VM.
// Deprecated: Use SSHKeysRef instead
// +optional
SSHKeys []*string `json:"sshKeys,omitempty"`

// SSHKeysRef is the SSH pub keys that will be used to access VM.
// +optional
SSHKeysRef []*IBMVPCResourceReference `json:"sshKeysRef,omitempty"`
}

// IBMVPCResourceReference is a reference to a specific VPC resource by ID or Name
// Only one of ID or Name may be specified. Specifying more than one will result in
// a validation error.
type IBMVPCResourceReference struct {
// ID of resource
// +kubebuilder:validation:MinLength=1
// +optional
ID *string `json:"id,omitempty"`

// Name of resource
// +kubebuilder:validation:MinLength=1
// +optional
Name *string `json:"name,omitempty"`
}

// IBMVPCMachineStatus defines the observed state of IBMVPCMachine.
Expand Down
36 changes: 0 additions & 36 deletions api/v1beta1/zz_generated.deepcopy.go

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

43 changes: 0 additions & 43 deletions cloud/scope/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,22 +157,6 @@ func (m *MachineScope) CreateMachine() (*vpcv1.Instance, error) {
}
}

if m.IBMVPCMachine.Spec.SSHKeysRef != nil {
if instancePrototype.Keys == nil {
instancePrototype.Keys = []vpcv1.KeyIdentityIntf{}
}
for _, sshKey := range m.IBMVPCMachine.Spec.SSHKeysRef {
keyID, err := fetchKeyID(sshKey, m)
if err != nil {
return nil, fmt.Errorf("error while fetching SSHKey: %v error: %v", sshKey, err)
}
key := &vpcv1.KeyIdentity{
ID: keyID,
}
instancePrototype.Keys = append(instancePrototype.Keys, key)
}
}

options.SetInstancePrototype(instancePrototype)
instance, _, err := m.IBMVPCClient.CreateInstance(options)
if err != nil {
Expand Down Expand Up @@ -343,30 +327,3 @@ func (m *MachineScope) GetBootstrapData() (string, error) {
}
return string(value), nil
}

func fetchKeyID(key *infrav1beta1.IBMVPCResourceReference, m *MachineScope) (*string, error) {
if key.ID != nil {
return key.ID, nil
}

if key.Name != nil {
keys, _, err := m.IBMVPCClient.ListKeys(&vpcv1.ListKeysOptions{})
if err != nil {
m.Logger.Error(err, "Failed to get keys")
return nil, err
}

for _, k := range keys.Keys {
if *k.Name == *key.Name {
m.Logger.V(3).Info("Key found with ID", "Key", *k.Name, "ID", *k.ID)
return k.ID, nil
}
}
}

if key.ID == nil && key.Name == nil {
return nil, fmt.Errorf("both ID and Name can't be nil")
}

return nil, fmt.Errorf("sshkey does not exist - failed to find Key ID")
}
Loading