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

OSASINFRA-3685: openstack: tag CAPI resources with InfraID #5262

Merged
merged 1 commit into from
Dec 15, 2024
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
OSASINFRA-3685: openstack: tag CAPI resources with InfraID
By default, OpenStack resources created by CAPI will be tagged (in the
OpenStack way) with `openshiftClusterID=<infraID>`.

`openshiftClusterID` is a well-known tag prefix in ShiftOnStack IPI.

Additional tags can be added via the `HostedCluster.Spec.Platform.OpenStack.Tags` field
when creating the HostedCluster with a given YAML file.
  • Loading branch information
EmilienM committed Dec 9, 2024
commit bba8234144b22fb225e9dc3584bf7a503e9c7760
5 changes: 5 additions & 0 deletions docs/content/how-to/openstack/create-openstack-cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,11 @@ example example 5 5 False
example-extra-az example 2 2 False False 4.17.0
```

## OpenStack resources tagging

The OpenStack resources created by the CAPI provider are tagged with `openshiftClusterID=<infraID>` but additional tags can be added to the resources
via the `HostedCluster.Spec.Platform.OpenStack.Tags` field when creating the HostedCluster with a given YAML file.

## Delete a HostedCluster

To delete a HostedCluster:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,11 @@ func reconcileOpenStackClusterSpec(hcluster *hyperv1.HostedCluster, openStackClu
openStackClusterSpec.ManagedSecurityGroups = &capo.ManagedSecurityGroups{
AllNodesSecurityGroupRules: defaultWorkerSecurityGroupRules(machineNetworksToStrings(machineNetworks)),
}
openStackClusterSpec.Tags = openStackPlatform.Tags

// Users are permitted to specify additional tags to be applied to the OpenStack resources
// but the default tag will be compliant with the OpenShift Cluster ID.
openStackClusterSpec.Tags = []string{"openshiftClusterID=" + hcluster.Spec.InfraID}
openStackClusterSpec.Tags = append(openStackClusterSpec.Tags, openStackPlatform.Tags...)

return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func TestReconcileOpenStackCluster(t *testing.T) {
name: "CAPO provisioned network and subnet",
hostedCluster: &hyperv1.HostedCluster{
Spec: hyperv1.HostedClusterSpec{
InfraID: "cluster-123",
Networking: hyperv1.ClusterNetworking{
MachineNetwork: []hyperv1.MachineNetworkEntry{{CIDR: *ipnet.MustParseCIDR("10.0.0.0/24")}},
},
Expand Down Expand Up @@ -71,13 +72,15 @@ func TestReconcileOpenStackCluster(t *testing.T) {
ManagedSecurityGroups: &capo.ManagedSecurityGroups{
AllNodesSecurityGroupRules: defaultWorkerSecurityGroupRules([]string{"10.0.0.0/24"}),
},
Tags: []string{"openshiftClusterID=cluster-123"},
},
wantErr: false,
},
{
name: "User provided network and subnet by ID on hosted cluster",
hostedCluster: &hyperv1.HostedCluster{
Spec: hyperv1.HostedClusterSpec{
InfraID: "cluster-123",
Networking: hyperv1.ClusterNetworking{
MachineNetwork: []hyperv1.MachineNetworkEntry{{CIDR: *ipnet.MustParseCIDR("192.168.1.0/24")}},
},
Expand Down Expand Up @@ -115,13 +118,15 @@ func TestReconcileOpenStackCluster(t *testing.T) {
ManagedSecurityGroups: &capo.ManagedSecurityGroups{
AllNodesSecurityGroupRules: defaultWorkerSecurityGroupRules([]string{"192.168.1.0/24"}),
},
Tags: []string{"openshiftClusterID=cluster-123"},
},
wantErr: false,
},
{
name: "User provided network and subnet by tag on hosted cluster",
hostedCluster: &hyperv1.HostedCluster{
Spec: hyperv1.HostedClusterSpec{
InfraID: "cluster-123",
Networking: hyperv1.ClusterNetworking{
MachineNetwork: []hyperv1.MachineNetworkEntry{{CIDR: *ipnet.MustParseCIDR("192.168.1.0/24")}},
},
Expand All @@ -144,6 +149,7 @@ func TestReconcileOpenStackCluster(t *testing.T) {
},
}},
},
Tags: []string{"hcp-id=123"},
}}}},
expectedOpenStackClusterSpec: capo.OpenStackClusterSpec{
IdentityRef: capo.OpenStackIdentityReference{
Expand Down Expand Up @@ -171,6 +177,7 @@ func TestReconcileOpenStackCluster(t *testing.T) {
ManagedSecurityGroups: &capo.ManagedSecurityGroups{
AllNodesSecurityGroupRules: defaultWorkerSecurityGroupRules([]string{"192.168.1.0/24"}),
},
Tags: []string{"openshiftClusterID=cluster-123", "hcp-id=123"},
},
wantErr: false,
},
Expand Down