Skip to content

Commit 13ad458

Browse files
committed
HIVE-2302: Save metadata.json opaquely
Well, mostly. Previously any time installer added a field to metadata.json, we would need to evaluate and possibly add a bespoke field and code path for it to make sure it was supplied to the destroyer at deprovision time. With this change, we're offloading metadata.json verbatim (except in some cases we have to scrub/replace credentials fields -- see HIVE-2804 / #2612) to a new Secret in the ClusterDeployment's namespace, referenced from a new field: ClusterDeployment.Spec.ClusterMetadata.MetadataJSONSecretRef. For legacy clusters -- those created before this change -- we attempt to retrofit the new Secret based on the legacy fields. This is best effort and may not always work. In the future (but not here!) instead of building the installer's ClusterMetadata structure for the destroyer with individual fields from the CD's ClusterMetadata, we'll unmarshal it directly from the contents of this Secret.
1 parent b49f0a1 commit 13ad458

22 files changed

+551
-42
lines changed

apis/hive/v1/aws/metadata.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@ package aws
44
type Metadata struct {
55
// HostedZoneRole is the role to assume when performing operations
66
// on a hosted zone owned by another account.
7+
// Deprecated. Use the Secret referenced by ClusterMetadata.MetadataJSONSecretRef instead. We
8+
// may stop populating this section in the future.
79
HostedZoneRole *string `json:"hostedZoneRole,omitempty"`
810
}

apis/hive/v1/azure/metadata.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@ package azure
33
// Metadata contains Azure metadata (e.g. for uninstalling the cluster).
44
type Metadata struct {
55
// ResourceGroupName is the name of the resource group in which the cluster resources were created.
6+
// Deprecated. Use the Secret referenced by ClusterMetadata.MetadataJSONSecretRef instead. We
7+
// may stop populating this section in the future.
68
ResourceGroupName *string `json:"resourceGroupName"`
79
}

apis/hive/v1/clusterdeployment_types.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,13 @@ type ClusterMetadata struct {
308308
// +optional
309309
AdminPasswordSecretRef *corev1.LocalObjectReference `json:"adminPasswordSecretRef,omitempty"`
310310

311-
// Platform holds platform-specific cluster metadata
311+
// MetaddataJSONSecretRef references the secret containing the metadata.json emitted by the
312+
// installer, potentially scrubbed for sensitive data.
313+
MetadataJSONSecretRef *corev1.LocalObjectReference `json:"metadataJSONSecretRef,omitempty"`
314+
315+
// Platform holds platform-specific cluster metadata.
316+
// Deprecated. Use the Secret referenced by MetadataJSONSecretRef instead. We may stop
317+
// populating this section in the future.
312318
// +optional
313319
Platform *ClusterPlatformMetadata `json:"platform,omitempty"`
314320
}

apis/hive/v1/gcp/metadata.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package gcp
33
// Metadata contains GCP metadata (e.g. for uninstalling the cluster).
44
type Metadata struct {
55
// NetworkProjectID is used for shared VPC setups
6+
// Deprecated. Use the Secret referenced by ClusterMetadata.MetadataJSONSecretRef instead. We
7+
// may stop populating this section in the future.
68
// +optional
79
NetworkProjectID *string `json:"networkProjectID,omitempty"`
810
}

apis/hive/v1/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crds/hive.openshift.io_clusterdeployments.yaml

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,27 @@ spec:
192192
during installation and used for tagging/naming resources in
193193
cloud providers.
194194
type: string
195+
metadataJSONSecretRef:
196+
description: |-
197+
MetaddataJSONSecretRef references the secret containing the metadata.json emitted by the
198+
installer, potentially scrubbed for sensitive data.
199+
properties:
200+
name:
201+
default: ""
202+
description: |-
203+
Name of the referent.
204+
This field is effectively required, but due to backwards compatibility is
205+
allowed to be empty. Instances of this type with an empty value here are
206+
almost certainly wrong.
207+
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
208+
type: string
209+
type: object
210+
x-kubernetes-map-type: atomic
195211
platform:
196-
description: Platform holds platform-specific cluster metadata
212+
description: |-
213+
Platform holds platform-specific cluster metadata.
214+
Deprecated. Use the Secret referenced by MetadataJSONSecretRef instead. We may stop
215+
populating this section in the future.
197216
properties:
198217
aws:
199218
description: AWS holds AWS-specific cluster metadata
@@ -202,14 +221,18 @@ spec:
202221
description: |-
203222
HostedZoneRole is the role to assume when performing operations
204223
on a hosted zone owned by another account.
224+
Deprecated. Use the Secret referenced by ClusterMetadata.MetadataJSONSecretRef instead. We
225+
may stop populating this section in the future.
205226
type: string
206227
type: object
207228
azure:
208229
description: Azure holds azure-specific cluster metadata
209230
properties:
210231
resourceGroupName:
211-
description: ResourceGroupName is the name of the resource
212-
group in which the cluster resources were created.
232+
description: |-
233+
ResourceGroupName is the name of the resource group in which the cluster resources were created.
234+
Deprecated. Use the Secret referenced by ClusterMetadata.MetadataJSONSecretRef instead. We
235+
may stop populating this section in the future.
213236
type: string
214237
required:
215238
- resourceGroupName
@@ -218,7 +241,10 @@ spec:
218241
description: GCP holds GCP-specific cluster metadata
219242
properties:
220243
networkProjectID:
221-
description: NetworkProjectID is used for shared VPC setups
244+
description: |-
245+
NetworkProjectID is used for shared VPC setups
246+
Deprecated. Use the Secret referenced by ClusterMetadata.MetadataJSONSecretRef instead. We
247+
may stop populating this section in the future.
222248
type: string
223249
type: object
224250
type: object

config/crds/hiveinternal.openshift.io_fakeclusterinstalls.yaml

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,27 @@ spec:
104104
during installation and used for tagging/naming resources in
105105
cloud providers.
106106
type: string
107+
metadataJSONSecretRef:
108+
description: |-
109+
MetaddataJSONSecretRef references the secret containing the metadata.json emitted by the
110+
installer, potentially scrubbed for sensitive data.
111+
properties:
112+
name:
113+
default: ""
114+
description: |-
115+
Name of the referent.
116+
This field is effectively required, but due to backwards compatibility is
117+
allowed to be empty. Instances of this type with an empty value here are
118+
almost certainly wrong.
119+
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
120+
type: string
121+
type: object
122+
x-kubernetes-map-type: atomic
107123
platform:
108-
description: Platform holds platform-specific cluster metadata
124+
description: |-
125+
Platform holds platform-specific cluster metadata.
126+
Deprecated. Use the Secret referenced by MetadataJSONSecretRef instead. We may stop
127+
populating this section in the future.
109128
properties:
110129
aws:
111130
description: AWS holds AWS-specific cluster metadata
@@ -114,14 +133,18 @@ spec:
114133
description: |-
115134
HostedZoneRole is the role to assume when performing operations
116135
on a hosted zone owned by another account.
136+
Deprecated. Use the Secret referenced by ClusterMetadata.MetadataJSONSecretRef instead. We
137+
may stop populating this section in the future.
117138
type: string
118139
type: object
119140
azure:
120141
description: Azure holds azure-specific cluster metadata
121142
properties:
122143
resourceGroupName:
123-
description: ResourceGroupName is the name of the resource
124-
group in which the cluster resources were created.
144+
description: |-
145+
ResourceGroupName is the name of the resource group in which the cluster resources were created.
146+
Deprecated. Use the Secret referenced by ClusterMetadata.MetadataJSONSecretRef instead. We
147+
may stop populating this section in the future.
125148
type: string
126149
required:
127150
- resourceGroupName
@@ -130,7 +153,10 @@ spec:
130153
description: GCP holds GCP-specific cluster metadata
131154
properties:
132155
networkProjectID:
133-
description: NetworkProjectID is used for shared VPC setups
156+
description: |-
157+
NetworkProjectID is used for shared VPC setups
158+
Deprecated. Use the Secret referenced by ClusterMetadata.MetadataJSONSecretRef instead. We
159+
may stop populating this section in the future.
134160
type: string
135161
type: object
136162
type: object

contrib/pkg/createcluster/create.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ type Options struct {
161161
AdoptAdminKubeConfig string
162162
AdoptInfraID string
163163
AdoptClusterID string
164+
AdoptMetadataJSON string
164165
AdoptAdminUsername string
165166
AdoptAdminPassword string
166167
MachineNetwork string
@@ -349,6 +350,7 @@ OpenShift Installer publishes all the services of the cluster like API server an
349350
flags.StringVar(&opt.AdoptAdminKubeConfig, "adopt-admin-kubeconfig", "", "Path to a cluster admin kubeconfig file for a cluster being adopted. (required if using --adopt)")
350351
flags.StringVar(&opt.AdoptInfraID, "adopt-infra-id", "", "Infrastructure ID for this cluster's cloud provider. (required if using --adopt)")
351352
flags.StringVar(&opt.AdoptClusterID, "adopt-cluster-id", "", "Cluster UUID used for telemetry. (required if using --adopt)")
353+
flags.StringVar(&opt.AdoptMetadataJSON, "adopt-metadata-json", "", "Path to a metadata.json file for a cluster being adopted. (optional)")
352354
flags.StringVar(&opt.AdoptAdminUsername, "adopt-admin-username", "", "Username for cluster web console administrator. (optional)")
353355
flags.StringVar(&opt.AdoptAdminPassword, "adopt-admin-password", "", "Password for cluster web console administrator. (optional)")
354356

@@ -506,13 +508,19 @@ func (o *Options) Validate(cmd *cobra.Command) error {
506508
return fmt.Errorf("--adopt-admin-kubeconfig does not exist: %s", o.AdoptAdminKubeConfig)
507509
}
508510

511+
if o.AdoptMetadataJSON != "" {
512+
if _, err := os.Stat(o.AdoptMetadataJSON); os.IsNotExist(err) {
513+
return fmt.Errorf("--adopt-metadata-json does not exist: %s", o.AdoptMetadataJSON)
514+
}
515+
}
516+
509517
// Admin username and password must both be specified if either are.
510518
if (o.AdoptAdminUsername != "" || o.AdoptAdminPassword != "") && !(o.AdoptAdminUsername != "" && o.AdoptAdminPassword != "") {
511519
return fmt.Errorf("--adopt-admin-username and --adopt-admin-password must be used together")
512520
}
513521
} else {
514-
if o.AdoptAdminKubeConfig != "" || o.AdoptInfraID != "" || o.AdoptClusterID != "" || o.AdoptAdminUsername != "" || o.AdoptAdminPassword != "" {
515-
return fmt.Errorf("cannot use adoption options without --adopt: --adopt-admin-kube-config, --adopt-infra-id, --adopt-cluster-id, --adopt-admin-username, --adopt-admin-password")
522+
if o.AdoptAdminKubeConfig != "" || o.AdoptInfraID != "" || o.AdoptClusterID != "" || o.AdoptMetadataJSON != "" || o.AdoptAdminUsername != "" || o.AdoptAdminPassword != "" {
523+
return fmt.Errorf("cannot use adoption options without --adopt: --adopt-admin-kube-config, --adopt-infra-id, --adopt-cluster-id, --adopt-metadata-json, --adopt-admin-username, --adopt-admin-password")
516524
}
517525
}
518526

@@ -658,6 +666,13 @@ func (o *Options) GenerateObjects() ([]runtime.Object, error) {
658666
if err != nil {
659667
return nil, err
660668
}
669+
if o.AdoptMetadataJSON != "" {
670+
metadataJSONBytes, err := os.ReadFile(o.AdoptMetadataJSON)
671+
if err != nil {
672+
return nil, err
673+
}
674+
builder.AdoptMetadataJSON = metadataJSONBytes
675+
}
661676
builder.Adopt = o.Adopt
662677
builder.AdoptInfraID = o.AdoptInfraID
663678
builder.AdoptClusterID = o.AdoptClusterID

0 commit comments

Comments
 (0)