Skip to content

Commit c0378f4

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 e10fdcc commit c0378f4

File tree

22 files changed

+550
-39
lines changed

22 files changed

+550
-39
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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,27 @@ spec:
180180
infraID:
181181
description: InfraID is an identifier for this cluster generated during installation and used for tagging/naming resources in cloud providers.
182182
type: string
183+
metadataJSONSecretRef:
184+
description: |-
185+
MetaddataJSONSecretRef references the secret containing the metadata.json emitted by the
186+
installer, potentially scrubbed for sensitive data.
187+
properties:
188+
name:
189+
default: ""
190+
description: |-
191+
Name of the referent.
192+
This field is effectively required, but due to backwards compatibility is
193+
allowed to be empty. Instances of this type with an empty value here are
194+
almost certainly wrong.
195+
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
196+
type: string
197+
type: object
198+
x-kubernetes-map-type: atomic
183199
platform:
184-
description: Platform holds platform-specific cluster metadata
200+
description: |-
201+
Platform holds platform-specific cluster metadata.
202+
Deprecated. Use the Secret referenced by MetadataJSONSecretRef instead. We may stop
203+
populating this section in the future.
185204
properties:
186205
aws:
187206
description: AWS holds AWS-specific cluster metadata
@@ -190,13 +209,18 @@ spec:
190209
description: |-
191210
HostedZoneRole is the role to assume when performing operations
192211
on a hosted zone owned by another account.
212+
Deprecated. Use the Secret referenced by ClusterMetadata.MetadataJSONSecretRef instead. We
213+
may stop populating this section in the future.
193214
type: string
194215
type: object
195216
azure:
196217
description: Azure holds azure-specific cluster metadata
197218
properties:
198219
resourceGroupName:
199-
description: ResourceGroupName is the name of the resource group in which the cluster resources were created.
220+
description: |-
221+
ResourceGroupName is the name of the resource group in which the cluster resources were created.
222+
Deprecated. Use the Secret referenced by ClusterMetadata.MetadataJSONSecretRef instead. We
223+
may stop populating this section in the future.
200224
type: string
201225
required:
202226
- resourceGroupName
@@ -205,7 +229,10 @@ spec:
205229
description: GCP holds GCP-specific cluster metadata
206230
properties:
207231
networkProjectID:
208-
description: NetworkProjectID is used for shared VPC setups
232+
description: |-
233+
NetworkProjectID is used for shared VPC setups
234+
Deprecated. Use the Secret referenced by ClusterMetadata.MetadataJSONSecretRef instead. We
235+
may stop populating this section in the future.
209236
type: string
210237
type: object
211238
type: object

config/crds/hiveinternal.openshift.io_fakeclusterinstalls.yaml

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,27 @@ spec:
9292
infraID:
9393
description: InfraID is an identifier for this cluster generated during installation and used for tagging/naming resources in cloud providers.
9494
type: string
95+
metadataJSONSecretRef:
96+
description: |-
97+
MetaddataJSONSecretRef references the secret containing the metadata.json emitted by the
98+
installer, potentially scrubbed for sensitive data.
99+
properties:
100+
name:
101+
default: ""
102+
description: |-
103+
Name of the referent.
104+
This field is effectively required, but due to backwards compatibility is
105+
allowed to be empty. Instances of this type with an empty value here are
106+
almost certainly wrong.
107+
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
108+
type: string
109+
type: object
110+
x-kubernetes-map-type: atomic
95111
platform:
96-
description: Platform holds platform-specific cluster metadata
112+
description: |-
113+
Platform holds platform-specific cluster metadata.
114+
Deprecated. Use the Secret referenced by MetadataJSONSecretRef instead. We may stop
115+
populating this section in the future.
97116
properties:
98117
aws:
99118
description: AWS holds AWS-specific cluster metadata
@@ -102,13 +121,18 @@ spec:
102121
description: |-
103122
HostedZoneRole is the role to assume when performing operations
104123
on a hosted zone owned by another account.
124+
Deprecated. Use the Secret referenced by ClusterMetadata.MetadataJSONSecretRef instead. We
125+
may stop populating this section in the future.
105126
type: string
106127
type: object
107128
azure:
108129
description: Azure holds azure-specific cluster metadata
109130
properties:
110131
resourceGroupName:
111-
description: ResourceGroupName is the name of the resource group in which the cluster resources were created.
132+
description: |-
133+
ResourceGroupName is the name of the resource group in which the cluster resources were created.
134+
Deprecated. Use the Secret referenced by ClusterMetadata.MetadataJSONSecretRef instead. We
135+
may stop populating this section in the future.
112136
type: string
113137
required:
114138
- resourceGroupName
@@ -117,7 +141,10 @@ spec:
117141
description: GCP holds GCP-specific cluster metadata
118142
properties:
119143
networkProjectID:
120-
description: NetworkProjectID is used for shared VPC setups
144+
description: |-
145+
NetworkProjectID is used for shared VPC setups
146+
Deprecated. Use the Secret referenced by ClusterMetadata.MetadataJSONSecretRef instead. We
147+
may stop populating this section in the future.
121148
type: string
122149
type: object
123150
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)