Skip to content

Commit

Permalink
Add conversion for SecretReference to string
Browse files Browse the repository at this point in the history
Signed-off-by: Tobias Giese <[email protected]>
  • Loading branch information
tobiasgiese committed Jul 13, 2021
1 parent a2acda3 commit 58a597e
Show file tree
Hide file tree
Showing 16 changed files with 108 additions and 126 deletions.
33 changes: 30 additions & 3 deletions api/v1alpha3/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package v1alpha3

import (
corev1 "k8s.io/api/core/v1"
conversion "k8s.io/apimachinery/pkg/conversion"
ctrlconversion "sigs.k8s.io/controller-runtime/pkg/conversion"

Expand Down Expand Up @@ -113,22 +114,43 @@ func Convert_v1alpha3_OpenStackClusterSpec_To_v1alpha4_OpenStackClusterSpec(in *
return autoConvert_v1alpha3_OpenStackClusterSpec_To_v1alpha4_OpenStackClusterSpec(in, out, s)
}

// Convert_v1alpha4_OpenStackClusterSpec_To_v1alpha3_OpenStackClusterSpec has to be added by us because we have to
// convert the Type of CloudsSecret from SecretReference to string.
func Convert_v1alpha4_OpenStackClusterSpec_To_v1alpha3_OpenStackClusterSpec(in *v1alpha4.OpenStackClusterSpec, out *OpenStackClusterSpec, s conversion.Scope) error {
if err := autoConvert_v1alpha4_OpenStackClusterSpec_To_v1alpha3_OpenStackClusterSpec(in, out, s); err != nil {
return err
}
out.CloudsSecret = new(corev1.SecretReference)
if in.CloudsSecret != nil {
out.CloudsSecret.Name = *in.CloudsSecret
}
return nil
}

// Convert_v1alpha3_OpenStackMachineSpec_To_v1alpha4_OpenStackMachineSpec is an autogenerated conversion function.
// v1alpha4 drops the field .UserDataSecret which is why we reuqire to define the function here.
func Convert_v1alpha3_OpenStackMachineSpec_To_v1alpha4_OpenStackMachineSpec(in *OpenStackMachineSpec, out *v1alpha4.OpenStackMachineSpec, s conversion.Scope) error {
return autoConvert_v1alpha3_OpenStackMachineSpec_To_v1alpha4_OpenStackMachineSpec(in, out, s)
}

// Convert_v1alpha3_OpenStackClusterSpec_To_v1alpha4_OpenStackClusterSpec has to be added by us for the new portOpts
// Convert_v1alpha4_Network_To_v1alpha3_Network has to be added by us for the new portOpts
// parameter in v1alpha4. There is no intention to support this parameter in v1alpha3, so the field is just dropped.
func Convert_v1alpha4_Network_To_v1alpha3_Network(in *v1alpha4.Network, out *Network, s conversion.Scope) error {
return autoConvert_v1alpha4_Network_To_v1alpha3_Network(in, out, s)
}

// Convert_v1alpha3_OpenStackClusterSpec_To_v1alpha4_OpenStackClusterSpec has to be added by us for the new ports
// Convert_v1alpha4_OpenStackMachineSpec_To_v1alpha3_OpenStackMachineSpec has to be added by us for the new ports
// parameter in v1alpha4. There is no intention to support this parameter in v1alpha3, so the field is just dropped.
// Further, we want to convert the Type of CloudsSecret from SecretReference to string.
func Convert_v1alpha4_OpenStackMachineSpec_To_v1alpha3_OpenStackMachineSpec(in *v1alpha4.OpenStackMachineSpec, out *OpenStackMachineSpec, s conversion.Scope) error {
return autoConvert_v1alpha4_OpenStackMachineSpec_To_v1alpha3_OpenStackMachineSpec(in, out, s)
if err := autoConvert_v1alpha4_OpenStackMachineSpec_To_v1alpha3_OpenStackMachineSpec(in, out, s); err != nil {
return err
}
out.CloudsSecret = new(corev1.SecretReference)
if in.CloudsSecret != nil {
out.CloudsSecret.Name = *in.CloudsSecret
}
return nil
}

func Convert_Slice_v1alpha4_Network_To_Slice_v1alpha3_Network(in *[]v1alpha4.Network, out *[]Network, s conversion.Scope) error {
Expand All @@ -154,3 +176,8 @@ func Convert_Slice_v1alpha3_Network_To_Slice_v1alpha4_Network(in *[]Network, out
}
return nil
}

func Convert_v1_SecretReference_To_string(in *corev1.SecretReference, out *string, s conversion.Scope) error {
out = &in.Name
return nil
}
44 changes: 30 additions & 14 deletions api/v1alpha3/zz_generated.conversion.go

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

4 changes: 2 additions & 2 deletions api/v1alpha4/openstackcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package v1alpha4

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha4"
)
Expand All @@ -33,7 +32,8 @@ type OpenStackClusterSpec struct {

// The name of the secret containing the openstack credentials
// +optional
CloudsSecret *corev1.SecretReference `json:"cloudsSecret"`
// +k8s:conversion-gen=false
CloudsSecret *string `json:"cloudsSecret,omitempty"`

// The name of the cloud to use from the clouds secret
// +optional
Expand Down
3 changes: 2 additions & 1 deletion api/v1alpha4/openstackmachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ type OpenStackMachineSpec struct {

// The name of the secret containing the openstack credentials
// +optional
CloudsSecret *corev1.SecretReference `json:"cloudsSecret"`
// +k8s:conversion-gen=false
CloudsSecret *string `json:"cloudsSecret,omitempty"`

// The name of the cloud to use from the clouds secret
// +optional
Expand Down
4 changes: 2 additions & 2 deletions api/v1alpha4/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -1104,16 +1104,7 @@ spec:
cloudsSecret:
description: The name of the secret containing the openstack
credentials
properties:
name:
description: Name is unique within a namespace to reference
a secret resource.
type: string
namespace:
description: Namespace defines the space within which
the secret name must be unique.
type: string
type: object
type: string
configDrive:
description: Config Drive support
type: boolean
Expand Down Expand Up @@ -1401,16 +1392,7 @@ spec:
type: string
cloudsSecret:
description: The name of the secret containing the openstack credentials
properties:
name:
description: Name is unique within a namespace to reference a
secret resource.
type: string
namespace:
description: Namespace defines the space within which the secret
name must be unique.
type: string
type: object
type: string
controlPlaneAvailabilityZones:
description: ControlPlaneAvailabilityZones is the az to deploy control
plane to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,16 +401,7 @@ spec:
type: string
cloudsSecret:
description: The name of the secret containing the openstack credentials
properties:
name:
description: Name is unique within a namespace to reference a
secret resource.
type: string
namespace:
description: Namespace defines the space within which the secret
name must be unique.
type: string
type: object
type: string
configDrive:
description: Config Drive support
type: boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,16 +343,7 @@ spec:
cloudsSecret:
description: The name of the secret containing the openstack
credentials
properties:
name:
description: Name is unique within a namespace to reference
a secret resource.
type: string
namespace:
description: Namespace defines the space within which
the secret name must be unique.
type: string
type: object
type: string
configDrive:
description: Config Drive support
type: boolean
Expand Down
16 changes: 4 additions & 12 deletions pkg/cloud/services/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,9 @@ func NewClientFromMachine(ctx context.Context, ctrlClient client.Client, openSta
var cloud clientconfig.Cloud
var caCert []byte

if openStackMachine.Spec.CloudsSecret != nil && openStackMachine.Spec.CloudsSecret.Name != "" {
namespace := openStackMachine.Spec.CloudsSecret.Namespace
if namespace == "" {
namespace = openStackMachine.Namespace
}
if *openStackMachine.Spec.CloudsSecret != "" {
var err error
cloud, caCert, err = getCloudFromSecret(ctx, ctrlClient, namespace, openStackMachine.Spec.CloudsSecret.Name, openStackMachine.Spec.CloudName)
cloud, caCert, err = getCloudFromSecret(ctx, ctrlClient, openStackMachine.Namespace, *openStackMachine.Spec.CloudsSecret, openStackMachine.Spec.CloudName)
if err != nil {
return nil, nil, err
}
Expand All @@ -63,13 +59,9 @@ func NewClientFromCluster(ctx context.Context, ctrlClient client.Client, openSta
var cloud clientconfig.Cloud
var caCert []byte

if openStackCluster.Spec.CloudsSecret != nil && openStackCluster.Spec.CloudsSecret.Name != "" {
namespace := openStackCluster.Spec.CloudsSecret.Namespace
if namespace == "" {
namespace = openStackCluster.Namespace
}
if *openStackCluster.Spec.CloudsSecret != "" {
var err error
cloud, caCert, err = getCloudFromSecret(ctx, ctrlClient, namespace, openStackCluster.Spec.CloudsSecret.Name, openStackCluster.Spec.CloudName)
cloud, caCert, err = getCloudFromSecret(ctx, ctrlClient, openStackCluster.Namespace, *openStackCluster.Spec.CloudsSecret, openStackCluster.Spec.CloudName)
if err != nil {
return nil, nil, err
}
Expand Down
9 changes: 3 additions & 6 deletions templates/cluster-template-external-cloud-provider.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ metadata:
name: ${CLUSTER_NAME}
spec:
cloudName: ${OPENSTACK_CLOUD}
cloudsSecret:
name: ${CLUSTER_NAME}-cloud-config
cloudsSecret: ${CLUSTER_NAME}-cloud-config
managedAPIServerLoadBalancer: true
managedSecurityGroups: true
nodeCidr: 10.6.0.0/24
Expand Down Expand Up @@ -74,8 +73,7 @@ spec:
image: ${OPENSTACK_IMAGE_NAME}
sshKeyName: ${OPENSTACK_SSH_KEY_NAME}
cloudName: ${OPENSTACK_CLOUD}
cloudsSecret:
name: ${CLUSTER_NAME}-cloud-config
cloudsSecret: ${CLUSTER_NAME}-cloud-config
---
apiVersion: cluster.x-k8s.io/v1alpha4
kind: MachineDeployment
Expand Down Expand Up @@ -109,8 +107,7 @@ spec:
template:
spec:
cloudName: ${OPENSTACK_CLOUD}
cloudsSecret:
name: ${CLUSTER_NAME}-cloud-config
cloudsSecret: ${CLUSTER_NAME}-cloud-config
flavor: ${OPENSTACK_NODE_MACHINE_FLAVOR}
image: ${OPENSTACK_IMAGE_NAME}
sshKeyName: ${OPENSTACK_SSH_KEY_NAME}
Expand Down
9 changes: 3 additions & 6 deletions templates/cluster-template-without-lb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ metadata:
name: ${CLUSTER_NAME}
spec:
cloudName: ${OPENSTACK_CLOUD}
cloudsSecret:
name: ${CLUSTER_NAME}-cloud-config
cloudsSecret: ${CLUSTER_NAME}-cloud-config
managedSecurityGroups: true
nodeCidr: 10.6.0.0/24
dnsNameservers:
Expand Down Expand Up @@ -102,8 +101,7 @@ spec:
image: ${OPENSTACK_IMAGE_NAME}
sshKeyName: ${OPENSTACK_SSH_KEY_NAME}
cloudName: ${OPENSTACK_CLOUD}
cloudsSecret:
name: ${CLUSTER_NAME}-cloud-config
cloudsSecret: ${CLUSTER_NAME}-cloud-config
---
apiVersion: cluster.x-k8s.io/v1alpha4
kind: MachineDeployment
Expand Down Expand Up @@ -137,8 +135,7 @@ spec:
template:
spec:
cloudName: ${OPENSTACK_CLOUD}
cloudsSecret:
name: ${CLUSTER_NAME}-cloud-config
cloudsSecret: ${CLUSTER_NAME}-cloud-config
flavor: ${OPENSTACK_NODE_MACHINE_FLAVOR}
image: ${OPENSTACK_IMAGE_NAME}
sshKeyName: ${OPENSTACK_SSH_KEY_NAME}
Expand Down
Loading

0 comments on commit 58a597e

Please sign in to comment.