Skip to content

Commit f8d3700

Browse files
Make authConfig as plain asset. Make infraenv as an asset
1 parent a594d3a commit f8d3700

File tree

5 files changed

+45
-35
lines changed

5 files changed

+45
-35
lines changed

pkg/asset/agent/common/infraenv.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package common
2+
3+
import (
4+
"github.com/google/uuid"
5+
6+
"github.com/openshift/installer/pkg/asset"
7+
)
8+
9+
// InfraEnvID is an asset that generates infraEnvID.
10+
type InfraEnvID struct {
11+
ID string
12+
}
13+
14+
var _ asset.Asset = (*InfraEnvID)(nil)
15+
16+
// Dependencies returns the assets on which the InfraEnv asset depends.
17+
func (a *InfraEnvID) Dependencies() []asset.Asset {
18+
return []asset.Asset{}
19+
}
20+
21+
// Generate generates the InfraEnvID for agent installer.
22+
func (a *InfraEnvID) Generate(dependencies asset.Parents) error {
23+
a.ID = uuid.New().String()
24+
return nil
25+
}
26+
27+
// Name returns the human-friendly name of the asset.
28+
func (a *InfraEnvID) Name() string {
29+
return "Agent Installer InfraEnv ID"
30+
}

pkg/asset/agent/common/utility.go

Lines changed: 0 additions & 11 deletions
This file was deleted.

pkg/asset/agent/gencrypto/authconfig.go

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,27 @@ const (
2727
InfraEnvKey LocalJWTKeyType = "infra_env_id"
2828
)
2929

30-
var _ asset.WritableAsset = (*AuthConfig)(nil)
30+
var _ asset.Asset = (*AuthConfig)(nil)
3131

3232
// Dependencies returns the assets on which the AuthConfig asset depends.
3333
func (a *AuthConfig) Dependencies() []asset.Asset {
34-
return []asset.Asset{}
34+
return []asset.Asset{
35+
&common.InfraEnvID{},
36+
}
3537
}
3638

3739
// Generate generates the auth config for agent installer APIs.
3840
func (a *AuthConfig) Generate(dependencies asset.Parents) error {
41+
infraEnvID := &common.InfraEnvID{}
42+
dependencies.Get(infraEnvID)
3943
PublicKey, PrivateKey, err := keyPairPEM()
4044
if err != nil {
4145
return err
4246
}
4347
a.PublicKey = PublicKey
4448
a.PrivateKey = PrivateKey
4549

46-
token, err := localJWTForKey(common.InfraEnvID, a.PrivateKey)
50+
token, err := localJWTForKey(infraEnvID.ID, a.PrivateKey)
4751
if err != nil {
4852
return err
4953
}
@@ -57,21 +61,6 @@ func (a *AuthConfig) Name() string {
5761
return "Agent Installer API Auth Config"
5862
}
5963

60-
// Load returns the auth config from disk.
61-
func (a *AuthConfig) Load(f asset.FileFetcher) (bool, error) {
62-
// The AuthConfig will not be needed by another asset so load is noop.
63-
// This is implemented because it is required by WritableAsset
64-
return false, nil
65-
}
66-
67-
// Files returns the files generated by the asset.
68-
func (a *AuthConfig) Files() []*asset.File {
69-
// Return empty array because File will never be loaded.
70-
return []*asset.File{}
71-
}
72-
73-
// Referenced from assisted-service.
74-
// https://github.com/openshift/assisted-service/blob/d3c0122452c74ad208055b8b6ee412812431a83f/internal/gencrypto/keys.go#L13-L54
7564
func keyPairPEM() (string, string, error) {
7665
priv, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
7766
if err != nil {
@@ -115,8 +104,6 @@ func keyPairPEM() (string, string, error) {
115104
return pubKeyPEM.String(), privKeyPEM.String(), nil
116105
}
117106

118-
// Referenced from assisted-service.
119-
// https://github.com/openshift/assisted-service/blob/d3c0122452c74ad208055b8b6ee412812431a83f/internal/gencrypto/token.go#L33-L50
120107
func localJWTForKey(id string, privateKkeyPem string) (string, error) {
121108
priv, err := jwt.ParseECPrivateKeyFromPEM([]byte(privateKkeyPem))
122109
if err != nil {

pkg/asset/agent/image/ignition.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ func (a *Ignition) Dependencies() []asset.Asset {
100100
&mirror.RegistriesConf{},
101101
&mirror.CaBundle{},
102102
&gencrypto.AuthConfig{},
103+
&common.InfraEnvID{},
103104
}
104105
}
105106

@@ -113,7 +114,8 @@ func (a *Ignition) Generate(dependencies asset.Parents) error {
113114
agentHostsAsset := &agentconfig.AgentHosts{}
114115
extraManifests := &manifests.ExtraManifests{}
115116
keyPairAsset := &gencrypto.AuthConfig{}
116-
dependencies.Get(agentManifests, agentConfigAsset, agentHostsAsset, extraManifests, keyPairAsset, agentWorkflow, clusterInfo, addNodesConfig)
117+
infraEnvAsset := &common.InfraEnvID{}
118+
dependencies.Get(agentManifests, agentConfigAsset, agentHostsAsset, extraManifests, keyPairAsset, agentWorkflow, clusterInfo, addNodesConfig, infraEnvAsset)
117119

118120
pwd := &password.KubeadminPassword{}
119121
dependencies.Get(pwd)
@@ -229,7 +231,7 @@ func (a *Ignition) Generate(dependencies asset.Parents) error {
229231

230232
releaseImageMirror := mirror.GetMirrorFromRelease(agentManifests.ClusterImageSet.Spec.ReleaseImage, registriesConfig)
231233

232-
infraEnvID := common.InfraEnvID
234+
infraEnvID := infraEnvAsset.ID
233235
logrus.Debug("Generated random infra-env id ", infraEnvID)
234236

235237
osImage, err := getOSImagesInfo(archName, openshiftVersion, streamGetter)

pkg/asset/agent/image/unconfigured_ignition.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,18 @@ func (a *UnconfiguredIgnition) Dependencies() []asset.Asset {
7878
&manifests.NMStateConfig{},
7979
&mirror.RegistriesConf{},
8080
&mirror.CaBundle{},
81+
&common.InfraEnvID{},
8182
}
8283
}
8384

8485
// Generate generates the agent installer unconfigured ignition.
8586
func (a *UnconfiguredIgnition) Generate(dependencies asset.Parents) error {
8687
infraEnvAsset := &manifests.InfraEnv{}
88+
infraEnvIDAsset := &common.InfraEnvID{}
8789
clusterImageSetAsset := &manifests.ClusterImageSet{}
8890
pullSecretAsset := &manifests.AgentPullSecret{}
8991
nmStateConfigs := &manifests.NMStateConfig{}
90-
dependencies.Get(infraEnvAsset, clusterImageSetAsset, pullSecretAsset, nmStateConfigs)
92+
dependencies.Get(infraEnvAsset, clusterImageSetAsset, pullSecretAsset, nmStateConfigs, infraEnvIDAsset)
9193

9294
infraEnv := infraEnvAsset.Config
9395
clusterImageSet := clusterImageSetAsset.Config
@@ -122,7 +124,7 @@ func (a *UnconfiguredIgnition) Generate(dependencies asset.Parents) error {
122124
registryCABundle := &mirror.CaBundle{}
123125
dependencies.Get(registriesConfig, registryCABundle)
124126

125-
infraEnvID := common.InfraEnvID
127+
infraEnvID := infraEnvIDAsset.ID
126128
logrus.Debug("Generated random infra-env id ", infraEnvID)
127129

128130
openshiftVersion, err := version.Version()

0 commit comments

Comments
 (0)