-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathassetcreate_test.go
More file actions
160 lines (146 loc) · 4.92 KB
/
assetcreate_test.go
File metadata and controls
160 lines (146 loc) · 4.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package store
import (
"context"
"os"
"path/filepath"
"reflect"
"testing"
"github.com/stretchr/testify/assert"
"github.com/openshift/installer/pkg/asset"
"github.com/openshift/installer/pkg/asset/targets"
)
const userProvidedAssets = `{
"*installconfig.baseDomain": {
"BaseDomain": "test-domain"
},
"*installconfig.clusterID": {
"ClusterID": "test-cluster-id"
},
"*installconfig.clusterName": {
"ClusterName": "test-cluster"
},
"*installconfig.platform": {
"none": {}
},
"*installconfig.pullSecret": {
"PullSecret": "{\"auths\": {\"example.com\": {\"auth\": \"test-auth\"}}}\n"
},
"*installconfig.sshPublicKey": {}
}`
const singleNodeBootstrapInPlaceInstallConfig = `
apiVersion: v1
baseDomain: test-domain
metadata:
name: test-cluster
platform:
none: {}
controlPlane:
replicas: 1
bootstrapInPlace:
installationDisk: /dev/sda
pullSecret: |
{
"auths": {
"example.com": {
"auth": "test-auth"
}
}
}
`
func TestCreatedAssetsAreNotDirty(t *testing.T) {
cases := []struct {
name string
targets []asset.WritableAsset
files map[string]string
}{
{
name: "install config",
targets: targets.InstallConfig,
files: map[string]string{stateFileName: userProvidedAssets},
},
{
name: "manifest templates",
targets: targets.ManifestTemplates,
files: map[string]string{stateFileName: userProvidedAssets},
},
{
name: "manifests",
targets: targets.Manifests,
files: map[string]string{stateFileName: userProvidedAssets},
},
{
name: "ignition configs",
targets: targets.IgnitionConfigs,
files: map[string]string{stateFileName: userProvidedAssets},
},
{
name: "single node bootstrap-in-place ignition config",
targets: targets.SingleNodeIgnitionConfig,
files: map[string]string{"install-config.yaml": singleNodeBootstrapInPlaceInstallConfig},
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
tempDir := t.TempDir()
for name, contents := range tc.files {
if err := os.WriteFile(filepath.Join(tempDir, name), []byte(contents), 0o666); err != nil { //nolint:gosec // no sensitive data
t.Fatalf("could not write the %s file: %v", name, err)
}
}
assetStore, err := newStore(tempDir)
if err != nil {
t.Fatalf("failed to create asset store: %v", err)
}
for _, a := range tc.targets {
if err := assetStore.Fetch(context.TODO(), a, tc.targets...); err != nil {
t.Fatalf("failed to fetch %q: %v", a.Name(), err)
}
if err := asset.PersistToFile(a, tempDir); err != nil {
t.Fatalf("failed to write asset %q to disk: %v", a.Name(), err)
}
}
newAssetStore, err := newStore(tempDir)
if err != nil {
t.Fatalf("failed to create new asset store: %v", err)
}
emptyAssets := map[string]bool{
"Arbiter Ignition Config": true, // no files for non arbiter cluster
"Arbiter Machines": true, // no files for the 'none' platform
"Master Machines": true, // no files for the 'none' platform
"Worker Machines": true, // no files for the 'none' platform
"Cluster API Manifests": true, // no files for the 'none' platform and ClusterAPIInstall feature gate not set
"Cluster API Machine Manifests": true, // no files for the 'none' platform and ClusterAPIInstall feature gate not set
"Metadata": true, // read-only
"Kubeadmin Password": true, // read-only
"InternalReleaseImageTLSSecret": true, // no files when NoRegistryClusterInstall feature gate is not set
"InternalReleaseImageRegistryAuthSecret": true, // no files when NoRegistryClusterInstall feature gate is not set
}
for _, a := range tc.targets {
name := a.Name()
newAsset := reflect.New(reflect.TypeOf(a).Elem()).Interface().(asset.WritableAsset)
if err := newAssetStore.Fetch(context.TODO(), newAsset, tc.targets...); err != nil {
t.Fatalf("failed to fetch %q in new store: %v", a.Name(), err)
}
assetState := newAssetStore.assets[reflect.TypeOf(a)]
if !emptyAssets[name] {
assert.Truef(t, assetState.presentOnDisk, "asset %q was not found on disk", a.Name())
}
}
assert.Equal(t, len(assetStore.assets), len(newAssetStore.assets), "new asset store does not have the same number of assets as original")
for _, a := range newAssetStore.assets {
if a.source == unfetched {
continue
}
if emptyAssets[a.asset.Name()] {
continue
}
originalAssetState, ok := assetStore.assets[reflect.TypeOf(a.asset)]
if !ok {
t.Fatalf("asset %q not found in original store", a.asset.Name())
}
assert.Equalf(t, originalAssetState.asset, a.asset, "fetched and generated asset %q are not equal", a.asset.Name())
assert.Equalf(t, stateFileSource, a.source, "asset %q was not fetched from the state file", a.asset.Name())
}
})
}
}