Skip to content

Commit 56571a1

Browse files
committed
update
1 parent 31c0354 commit 56571a1

File tree

2 files changed

+64
-5
lines changed

2 files changed

+64
-5
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
Copyright 2021 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package contract
18+
19+
import (
20+
"sync"
21+
)
22+
23+
// InfrastructureClusterTemplateContract encodes information about the Cluster API contract for InfrastructureClusterTemplate objects
24+
// like DockerClusterTemplates, AWSClusterTemplates, etc.
25+
type InfrastructureClusterTemplateContract struct{}
26+
27+
var infrastructureClusterTemplate *InfrastructureClusterTemplateContract
28+
var onceInfrastructureClusterTemplate sync.Once
29+
30+
// InfrastructureClusterTemplate provides access to the information about the Cluster API contract for InfrastructureClusterTemplate objects.
31+
func InfrastructureClusterTemplate() *InfrastructureClusterTemplateContract {
32+
onceInfrastructureClusterTemplate.Do(func() {
33+
infrastructureClusterTemplate = &InfrastructureClusterTemplateContract{}
34+
})
35+
return infrastructureClusterTemplate
36+
}
37+
38+
// Template provides access to the template.
39+
func (c *InfrastructureClusterTemplateContract) Template() *InfrastructureClusterTemplateTemplate {
40+
return &InfrastructureClusterTemplateTemplate{}
41+
}
42+
43+
// InfrastructureClusterTemplateTemplate provides a helper struct for working with the template in an InfrastructureClusterTemplate..
44+
type InfrastructureClusterTemplateTemplate struct{}
45+
46+
// Metadata provides access to the metadata of a template.
47+
func (c *InfrastructureClusterTemplateTemplate) Metadata() *Metadata {
48+
return &Metadata{
49+
path: Path{"spec", "template", "spec", "metadata"},
50+
}
51+
}

test/e2e/clusterclass_rollout.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,13 +265,14 @@ func assertMetadataOnClusterObjects(ctx context.Context, clusterProxy framework.
265265
clusterObjects := getClusterObjects(ctx, g, clusterProxy, cluster)
266266

267267
// InfrastructureCluster
268+
infrastructureClusterTemplateTemplateMetadata := mustMetadata(contract.InfrastructureClusterTemplate().Template().Metadata().Get(clusterClassObjects.InfrastructureClusterTemplate))
268269
g.Expect(clusterObjects.InfrastructureCluster.GetLabels()).To(BeEquivalentTo(
269270
union(
270271
map[string]string{
271272
clusterv1.ClusterNameLabel: cluster.Name,
272273
clusterv1.ClusterTopologyOwnedLabel: "",
273274
},
274-
templateMetadata(clusterClassObjects.InfrastructureClusterTemplate).Labels,
275+
infrastructureClusterTemplateTemplateMetadata.Labels,
275276
),
276277
))
277278
g.Expect(clusterObjects.InfrastructureCluster.GetAnnotations()).To(BeEquivalentTo(
@@ -280,7 +281,7 @@ func assertMetadataOnClusterObjects(ctx context.Context, clusterProxy framework.
280281
clusterv1.TemplateClonedFromGroupKindAnnotation: groupKind(clusterClass.Spec.Infrastructure.Ref),
281282
clusterv1.TemplateClonedFromNameAnnotation: clusterClass.Spec.Infrastructure.Ref.Name,
282283
},
283-
templateMetadata(clusterClassObjects.InfrastructureClusterTemplate).Annotations,
284+
infrastructureClusterTemplateTemplateMetadata.Annotations,
284285
),
285286
))
286287

@@ -307,8 +308,8 @@ func assertMetadataOnClusterObjects(ctx context.Context, clusterProxy framework.
307308
templateMetadata(clusterClassObjects.ControlPlaneTemplate).Annotations,
308309
),
309310
))
310-
controlPlaneMachineTemplateMetadata, err := contract.ControlPlane().MachineTemplate().Metadata().Get(clusterObjects.ControlPlane)
311-
g.Expect(err).NotTo(HaveOccurred())
311+
312+
controlPlaneMachineTemplateMetadata := mustMetadata(contract.ControlPlane().MachineTemplate().Metadata().Get(clusterObjects.ControlPlane))
312313
g.Expect(controlPlaneMachineTemplateMetadata.Labels).To(BeEquivalentTo(
313314
union(
314315
map[string]string{
@@ -672,7 +673,14 @@ func assertMetadataOnClusterObjects(ctx context.Context, clusterProxy framework.
672673
}
673674

674675
By("All cluster objects have the right labels, annotations and selectors")
675-
}, 10*time.Minute, 1*time.Second).Should(Succeed()) // FIXME: timeouts, look at actual rollout times
676+
}, 10*time.Minute, 1*time.Second).Should(Succeed()) // FIXME: timeouts, look at actual rollout times => check if we should wait before calling this func for complete rollout (including nodes)
677+
}
678+
679+
func mustMetadata(metadata *clusterv1.ObjectMeta, err error) *clusterv1.ObjectMeta {
680+
if err != nil {
681+
panic(err)
682+
}
683+
return metadata
676684
}
677685

678686
func getMDTopology(cluster *clusterv1.Cluster, md *clusterv1.MachineDeployment) *clusterv1.MachineDeploymentTopology {

0 commit comments

Comments
 (0)