Skip to content

Commit

Permalink
Revert "Remove infrastructure.giantswarm.io/v1alpha2 types and checks (
Browse files Browse the repository at this point in the history
…#3875)" (#3877)

This reverts commit 9a2b271.
  • Loading branch information
kuosandys authored Nov 10, 2022
1 parent ecdaae8 commit ba56216
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ProviderCluster } from 'MAPI/types';
import * as capav1beta1 from 'model/services/mapi/capav1beta1';
import * as capgv1beta1 from 'model/services/mapi/capgv1beta1';
import * as capzv1beta1 from 'model/services/mapi/capzv1beta1';
import * as infrav1alpha2 from 'model/services/mapi/infrastructurev1alpha2';
import * as infrav1alpha3 from 'model/services/mapi/infrastructurev1alpha3';
import React from 'react';
import ClusterDetailWidget from 'UI/Display/MAPI/clusters/ClusterDetail/ClusterDetailWidget';
Expand Down Expand Up @@ -51,8 +52,10 @@ const ClusterDetailWidgetProvider: React.FC<
<ClusterDetailWidgetProviderAzure
providerCluster={providerCluster as capzv1beta1.IAzureCluster}
/>
) : kind === infrav1alpha3.AWSCluster &&
apiVersion === infrav1alpha3.ApiVersion ? (
) : (kind === infrav1alpha2.AWSCluster &&
apiVersion === infrav1alpha2.ApiVersion) ||
(kind === infrav1alpha3.AWSCluster &&
apiVersion === infrav1alpha3.ApiVersion) ? (
<ClusterDetailWidgetProviderAWS
providerCluster={providerCluster as infrav1alpha3.IAWSCluster}
/>
Expand Down
27 changes: 19 additions & 8 deletions src/components/MAPI/clusters/ClusterDetail/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { IHttpClient } from 'model/clients/HttpClient';
import { Constants, Providers } from 'model/constants';
import * as capiv1beta1 from 'model/services/mapi/capiv1beta1';
import * as capzv1beta1 from 'model/services/mapi/capzv1beta1';
import * as infrav1alpha2 from 'model/services/mapi/infrastructurev1alpha2';
import * as infrav1alpha3 from 'model/services/mapi/infrastructurev1alpha3';
import * as legacyCredentials from 'model/services/mapi/legacy/credentials';
import * as metav1 from 'model/services/mapi/metav1';
Expand Down Expand Up @@ -63,16 +64,18 @@ export async function updateClusterDescription(

if (
providerCluster &&
providerCluster.kind === infrav1alpha3.AWSCluster &&
providerCluster.apiVersion === infrav1alpha3.ApiVersion &&
((providerCluster.kind === infrav1alpha2.AWSCluster &&
providerCluster.apiVersion === infrav1alpha2.ApiVersion) ||
(providerCluster.kind === infrav1alpha3.AWSCluster &&
providerCluster.apiVersion === infrav1alpha3.ApiVersion)) &&
typeof providerCluster.spec !== 'undefined'
) {
providerCluster.spec.cluster.description = newDescription;

const updatedProviderCluster = await infrav1alpha3.updateAWSCluster(
httpClientFactory(),
auth,
providerCluster
providerCluster as infrav1alpha3.IAWSCluster
);

mutate(
Expand Down Expand Up @@ -159,6 +162,8 @@ export async function deleteProviderClusterForCluster(

const { kind, apiVersion } = providerCluster;
switch (true) {
case kind === infrav1alpha2.AWSCluster &&
apiVersion === infrav1alpha2.ApiVersion:
case kind === infrav1alpha3.AWSCluster &&
apiVersion === infrav1alpha3.ApiVersion: {
const client = httpClientFactory();
Expand Down Expand Up @@ -204,7 +209,7 @@ export async function deleteControlPlaneNodesForCluster(
await infrav1alpha3.deleteAWSControlPlane(
client,
auth,
controlPlaneNode
controlPlaneNode as infrav1alpha3.IAWSControlPlane
);

controlPlaneNode.metadata.deletionTimestamp = new Date().toISOString();
Expand All @@ -218,7 +223,7 @@ export async function deleteControlPlaneNodesForCluster(
await infrav1alpha3.deleteG8sControlPlane(
client,
auth,
controlPlaneNode
controlPlaneNode as infrav1alpha3.IG8sControlPlane
);

controlPlaneNode.metadata.deletionTimestamp = new Date().toISOString();
Expand Down Expand Up @@ -251,8 +256,10 @@ export async function deleteClusterResources(
const kind = cluster.spec?.infrastructureRef?.kind;
const apiVersion = cluster.spec?.infrastructureRef?.apiVersion;
if (
kind === infrav1alpha3.AWSCluster &&
apiVersion === infrav1alpha3.ApiVersion
(kind === infrav1alpha2.AWSCluster &&
apiVersion === infrav1alpha2.ApiVersion) ||
(kind === infrav1alpha3.AWSCluster &&
apiVersion === infrav1alpha3.ApiVersion)
) {
await deleteProviderClusterForCluster(httpClientFactory, auth, cluster);
await deleteControlPlaneNodesForCluster(httpClientFactory, auth, cluster);
Expand Down Expand Up @@ -478,7 +485,11 @@ export async function switchClusterToHACPNodes(
controlPlaneNode.spec.replicas = Constants.AWS_HA_MASTERS_MAX_NODES;

requests.push(
infrav1alpha3.updateG8sControlPlane(client, auth, controlPlaneNode)
infrav1alpha3.updateG8sControlPlane(
client,
auth,
controlPlaneNode as infrav1alpha3.IG8sControlPlane
)
);
}
}
Expand Down
18 changes: 13 additions & 5 deletions src/components/MAPI/clusters/CreateCluster/patches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { determineRandomAZs, getSupportedAvailabilityZones } from 'MAPI/utils';
import { Constants } from 'model/constants';
import * as capiv1beta1 from 'model/services/mapi/capiv1beta1';
import * as capzv1beta1 from 'model/services/mapi/capzv1beta1';
import * as infrav1alpha2 from 'model/services/mapi/infrastructurev1alpha2';
import * as infrav1alpha3 from 'model/services/mapi/infrastructurev1alpha3';
import { compare } from 'utils/semver';

Expand Down Expand Up @@ -43,8 +44,10 @@ export function withClusterReleaseVersion(
return (cluster, providerCluster, controlPlaneNodes) => {
const hasNonNamespacedResources =
providerCluster &&
providerCluster.kind === infrav1alpha3.AWSCluster &&
providerCluster.apiVersion === infrav1alpha3.ApiVersion &&
((providerCluster.kind === infrav1alpha2.AWSCluster &&
providerCluster.apiVersion === infrav1alpha2.ApiVersion) ||
(providerCluster.kind === infrav1alpha3.AWSCluster &&
providerCluster.apiVersion === infrav1alpha3.ApiVersion)) &&
compare(newVersion, Constants.AWS_NAMESPACED_CLUSTERS_VERSION) < 0;
const defaultNamespace = 'default';

Expand Down Expand Up @@ -111,8 +114,10 @@ export function withClusterDescription(newDescription: string): ClusterPatch {

if (
providerCluster &&
providerCluster.kind === infrav1alpha3.AWSCluster &&
providerCluster.apiVersion === infrav1alpha3.ApiVersion &&
((providerCluster.kind === infrav1alpha2.AWSCluster &&
providerCluster.apiVersion === infrav1alpha2.ApiVersion) ||
(providerCluster.kind === infrav1alpha3.AWSCluster &&
providerCluster.apiVersion === infrav1alpha3.ApiVersion)) &&
providerCluster.spec
) {
providerCluster.spec.cluster.description = newDescription;
Expand Down Expand Up @@ -144,7 +149,10 @@ export function withClusterControlPlaneNodesCount(count: number): ClusterPatch {
const supportedAZs = getSupportedAvailabilityZones().all;

for (const controlPlaneNode of controlPlaneNodes) {
if (controlPlaneNode.apiVersion !== infrav1alpha3.ApiVersion) {
if (
controlPlaneNode.apiVersion !== infrav1alpha2.ApiVersion &&
controlPlaneNode.apiVersion !== infrav1alpha3.ApiVersion
) {
continue;
}

Expand Down
13 changes: 11 additions & 2 deletions src/components/MAPI/clusters/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import * as capgv1beta1 from 'model/services/mapi/capgv1beta1';
import * as capiv1beta1 from 'model/services/mapi/capiv1beta1';
import * as capzv1beta1 from 'model/services/mapi/capzv1beta1';
import * as corev1 from 'model/services/mapi/corev1';
import * as infrav1alpha2 from 'model/services/mapi/infrastructurev1alpha2';
import * as infrav1alpha3 from 'model/services/mapi/infrastructurev1alpha3';
import * as metav1 from 'model/services/mapi/metav1';
import * as releasev1alpha1 from 'model/services/mapi/releasev1alpha1';
Expand Down Expand Up @@ -313,6 +314,8 @@ export function createDefaultCluster(config: {
const { kind, apiVersion } = config.providerCluster;
switch (true) {
case kind === capzv1beta1.AzureCluster:
case kind === infrav1alpha2.AWSCluster &&
apiVersion === infrav1alpha2.ApiVersion:
case kind === infrav1alpha3.AWSCluster &&
apiVersion === infrav1alpha3.ApiVersion:
return createDefaultV1Alpha3Cluster(config);
Expand Down Expand Up @@ -372,6 +375,8 @@ export function createDefaultControlPlaneNodes(config: {
switch (true) {
case kind === capzv1beta1.AzureCluster:
return [createDefaultAzureMachine(config)];
case kind === infrav1alpha2.AWSCluster &&
apiVersion === infrav1alpha2.ApiVersion:
case kind === infrav1alpha3.AWSCluster &&
apiVersion === infrav1alpha3.ApiVersion: {
const name = generateUID(5);
Expand Down Expand Up @@ -652,6 +657,8 @@ export async function createCluster(
break;
}

case kind === infrav1alpha2.AWSCluster &&
apiVersion === infrav1alpha2.ApiVersion:
case kind === infrav1alpha3.AWSCluster &&
apiVersion === infrav1alpha3.ApiVersion: {
// AWS cluster
Expand Down Expand Up @@ -736,13 +743,13 @@ export async function createCluster(
return infrav1alpha3.createAWSControlPlane(
httpClientFactory(),
auth,
n
n as infrav1alpha3.IAWSControlPlane
);
case infrav1alpha3.G8sControlPlane:
return infrav1alpha3.createG8sControlPlane(
httpClientFactory(),
auth,
n
n as infrav1alpha3.IG8sControlPlane
);
default:
return Promise.reject(
Expand Down Expand Up @@ -919,6 +926,8 @@ export function getClusterConditions(
statuses.isUpgrading = isClusterUpgrading(cluster);
break;

case kind === infrav1alpha2.AWSCluster &&
apiVersion === infrav1alpha2.ApiVersion:
case kind === infrav1alpha3.AWSCluster &&
apiVersion === infrav1alpha3.ApiVersion: {
if (!providerCluster) break;
Expand Down
9 changes: 9 additions & 0 deletions src/components/MAPI/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import * as capiv1beta1 from 'model/services/mapi/capiv1beta1';
import * as capzexpv1alpha3 from 'model/services/mapi/capzv1alpha3/exp';
import * as capzv1beta1 from 'model/services/mapi/capzv1beta1';
import * as gscorev1alpha1 from 'model/services/mapi/gscorev1alpha1';
import * as infrav1alpha2 from 'model/services/mapi/infrastructurev1alpha2';
import * as infrav1alpha3 from 'model/services/mapi/infrastructurev1alpha3';

export type ControlPlaneNode =
| capzv1beta1.IAzureMachine
| infrav1alpha2.IAWSControlPlane
| infrav1alpha2.IG8sControlPlane
| infrav1alpha3.IAWSControlPlane
| infrav1alpha3.IG8sControlPlane
| capav1beta1.IAWSMachineTemplate
Expand All @@ -17,6 +20,8 @@ export type ControlPlaneNode =

export type ControlPlaneNodeList =
| capzv1beta1.IAzureMachineList
| infrav1alpha2.IAWSControlPlaneList
| infrav1alpha2.IG8sControlPlaneList
| infrav1alpha3.IAWSControlPlaneList
| infrav1alpha3.IG8sControlPlaneList
| capav1beta1.IAWSMachineTemplateList
Expand All @@ -29,13 +34,15 @@ export type ClusterList = capiv1beta1.IClusterList;

export type ProviderCluster =
| capzv1beta1.IAzureCluster
| infrav1alpha2.IAWSCluster
| infrav1alpha3.IAWSCluster
| capav1beta1.IAWSCluster
| capgv1beta1.IGCPCluster
| undefined;

export type ProviderClusterList =
| capzv1beta1.IAzureClusterList
| infrav1alpha2.IAWSClusterList
| infrav1alpha3.IAWSClusterList
| capav1beta1.IAWSClusterList
| capgv1beta1.IGCPClusterList;
Expand All @@ -53,6 +60,7 @@ export type NodePoolList =
export type ProviderNodePool =
| capzexpv1alpha3.IAzureMachinePool
| capzv1beta1.IAzureMachinePool
| infrav1alpha2.IAWSMachineDeployment
| infrav1alpha3.IAWSMachineDeployment
| capav1beta1.IAWSMachinePool
| capgv1beta1.IGCPMachineTemplate
Expand All @@ -61,6 +69,7 @@ export type ProviderNodePool =
export type ProviderNodePoolList =
| capzexpv1alpha3.IAzureMachinePoolList
| capzv1beta1.IAzureMachinePoolList
| infrav1alpha2.IAWSMachineDeploymentList
| infrav1alpha3.IAWSMachineDeploymentList
| capav1beta1.IAWSMachinePoolList
| capgv1beta1.IGCPMachineTemplateList;
Expand Down
19 changes: 19 additions & 0 deletions src/components/MAPI/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as capiexpv1alpha3 from 'model/services/mapi/capiv1alpha3/exp';
import * as capiv1beta1 from 'model/services/mapi/capiv1beta1';
import * as capzexpv1alpha3 from 'model/services/mapi/capzv1alpha3/exp';
import * as capzv1beta1 from 'model/services/mapi/capzv1beta1';
import * as infrav1alpha2 from 'model/services/mapi/infrastructurev1alpha2';
import * as infrav1alpha3 from 'model/services/mapi/infrastructurev1alpha3';
import * as metav1 from 'model/services/mapi/metav1';
import * as securityv1alpha1 from 'model/services/mapi/securityv1alpha1';
Expand Down Expand Up @@ -188,6 +189,8 @@ export async function fetchNodePoolListForCluster(

break;

case kind === infrav1alpha2.AWSCluster &&
apiVersion === infrav1alpha2.ApiVersion:
case kind === infrav1alpha3.AWSCluster &&
apiVersion === infrav1alpha3.ApiVersion:
list = await capiv1beta1.getMachineDeploymentList(
Expand Down Expand Up @@ -262,6 +265,8 @@ export function fetchNodePoolListForClusterKey(
namespace,
});

case kind === infrav1alpha2.AWSCluster &&
apiVersion === infrav1alpha2.ApiVersion:
case kind === infrav1alpha3.AWSCluster &&
apiVersion === infrav1alpha3.ApiVersion:
return capiv1beta1.getMachineDeploymentListKey({
Expand Down Expand Up @@ -647,6 +652,8 @@ export async function fetchControlPlaneNodesForCluster(
return cpNodes.items;
}

case kind === infrav1alpha2.AWSCluster &&
apiVersion === infrav1alpha2.ApiVersion:
case kind === infrav1alpha3.AWSCluster &&
apiVersion === infrav1alpha3.ApiVersion: {
const [awsCP, g8sCP] = await Promise.allSettled([
Expand Down Expand Up @@ -731,6 +738,8 @@ export function fetchControlPlaneNodesForClusterKey(
namespace: cluster.metadata.namespace,
});

case kind === infrav1alpha2.AWSCluster &&
apiVersion === infrav1alpha2.ApiVersion:
case kind === infrav1alpha3.AWSCluster &&
apiVersion === infrav1alpha3.ApiVersion:
return infrav1alpha3.getAWSControlPlaneListKey({
Expand Down Expand Up @@ -786,6 +795,8 @@ export async function fetchProviderClusterForCluster(
infrastructureRef.name
);

case kind === infrav1alpha2.AWSCluster &&
apiVersion === infrav1alpha2.ApiVersion:
case kind === infrav1alpha3.AWSCluster &&
apiVersion === infrav1alpha3.ApiVersion:
return infrav1alpha3.getAWSCluster(
Expand Down Expand Up @@ -825,6 +836,8 @@ export function fetchProviderClusterForClusterKey(cluster: Cluster) {
infrastructureRef.name
);

case kind === infrav1alpha2.AWSCluster &&
apiVersion === infrav1alpha2.ApiVersion:
case kind === infrav1alpha3.AWSCluster &&
apiVersion === infrav1alpha3.ApiVersion:
return infrav1alpha3.getAWSClusterKey(
Expand Down Expand Up @@ -1209,6 +1222,8 @@ export function getClusterDescription(

const { kind, apiVersion } = infrastructureRef;
switch (true) {
case kind === infrav1alpha2.AWSCluster &&
apiVersion === infrav1alpha2.ApiVersion:
case kind === infrav1alpha3.AWSCluster &&
apiVersion === infrav1alpha3.ApiVersion:
return (
Expand Down Expand Up @@ -1249,6 +1264,8 @@ export function getProviderClusterLocation(
(providerCluster as capzv1beta1.IAzureCluster).spec?.location ?? ''
);

case kind === infrav1alpha2.AWSCluster &&
apiVersion === infrav1alpha2.ApiVersion:
case kind === infrav1alpha3.AWSCluster &&
apiVersion === infrav1alpha3.ApiVersion: {
const region = (providerCluster as infrav1alpha3.IAWSCluster).spec
Expand Down Expand Up @@ -1489,6 +1506,8 @@ export function supportsClientCertificates(cluster: Cluster): boolean {
case kind === capzv1beta1.AzureCluster:
return true;

case kind === infrav1alpha2.AWSCluster &&
apiVersion === infrav1alpha2.ApiVersion:
case kind === infrav1alpha3.AWSCluster &&
apiVersion === infrav1alpha3.ApiVersion: {
const releaseVersion = getClusterReleaseVersion(cluster);
Expand Down
4 changes: 2 additions & 2 deletions src/components/MAPI/workernodes/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export async function updateNodePoolDescription(
providerNodePool = await infrav1alpha3.updateAWSMachineDeployment(
client,
auth,
providerNodePool
providerNodePool as infrav1alpha3.IAWSMachineDeployment
);

mutate(
Expand Down Expand Up @@ -637,7 +637,7 @@ export async function updateNodePoolScaling(
providerNodePool = await infrav1alpha3.updateAWSMachineDeployment(
client,
auth,
providerNodePool
providerNodePool as infrav1alpha3.IAWSMachineDeployment
);

mutate(
Expand Down
1 change: 1 addition & 0 deletions src/model/services/mapi/infrastructurev1alpha2/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './types';
Loading

0 comments on commit ba56216

Please sign in to comment.