Skip to content

Commit e8e19d2

Browse files
committed
Change BMC CA logic to use assets
Signed-off-by: Dmitry Tantsur <[email protected]>
1 parent a502e90 commit e8e19d2

File tree

3 files changed

+103
-17
lines changed

3 files changed

+103
-17
lines changed

data/data/bootstrap/bootstrap-in-place/files/opt/openshift/bootstrap-in-place/bootstrap-in-place-post-reboot.sh

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,6 @@ function signal_bootstrap_complete {
2424
done
2525
}
2626

27-
function create_bmc_verify_ca_cm {
28-
local ca_storage_dir="/tmp/cert/ca/bmc"
29-
local name="bmc-verify-ca"
30-
local ns="openshift-machine-api"
31-
32-
[[ -d "$ca_storage_dir" ]] || return
33-
34-
until [ "$(oc get cm "${name}" -n "${ns}")" -eq 0 ];
35-
do
36-
echo "Creating bmc verify ca configmap ..."
37-
oc create cm "${name}" -n "${ns}" --from-file="${ca_storage_dir}" || true
38-
sleep 5
39-
done
40-
}
41-
4227
function release_lease {
4328
local ns="$1"
4429
local lease="$2"
@@ -145,7 +130,6 @@ function clean {
145130

146131
wait_for_api
147132
signal_bootstrap_complete
148-
create_bmc_verify_ca_cm
149133
release_cvo_lease
150134
release_cpc_lease
151135
restore_cvo_overrides

pkg/asset/manifests/operators.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ func (m *Manifests) Dependencies() []asset.Asset {
8585
&bootkube.MachineConfigServerCAConfigMap{},
8686
&bootkube.MachineConfigServerTLSSecret{},
8787
&bootkube.OpenshiftConfigSecretPullSecret{},
88+
&tls.BMCVerifyCAConfigMap{},
8889
}
8990
}
9091

@@ -101,8 +102,9 @@ func (m *Manifests) Generate(_ context.Context, dependencies asset.Parents) erro
101102
clusterCSIDriverConfig := &ClusterCSIDriverConfig{}
102103
imageDigestMirrorSet := &ImageDigestMirrorSet{}
103104
mcoCfgTemplate := &manifests.MCO{}
105+
bmcVerifyCAConfigMap := &tls.BMCVerifyCAConfigMap{}
104106

105-
dependencies.Get(installConfig, ingress, dns, network, infra, proxy, scheduler, imageContentSourcePolicy, imageDigestMirrorSet, clusterCSIDriverConfig, mcoCfgTemplate)
107+
dependencies.Get(installConfig, ingress, dns, network, infra, proxy, scheduler, imageContentSourcePolicy, imageDigestMirrorSet, clusterCSIDriverConfig, mcoCfgTemplate, bmcVerifyCAConfigMap)
106108

107109
redactedConfig, err := redactedInstallConfig(*installConfig.Config)
108110
if err != nil {
@@ -140,6 +142,7 @@ func (m *Manifests) Generate(_ context.Context, dependencies asset.Parents) erro
140142
m.FileList = append(m.FileList, imageContentSourcePolicy.Files()...)
141143
m.FileList = append(m.FileList, clusterCSIDriverConfig.Files()...)
142144
m.FileList = append(m.FileList, imageDigestMirrorSet.Files()...)
145+
m.FileList = append(m.FileList, bmcVerifyCAConfigMap.Files()...)
143146

144147
asset.SortFiles(m.FileList)
145148

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package tls
2+
3+
import (
4+
"context"
5+
"path"
6+
7+
"github.com/pkg/errors"
8+
corev1 "k8s.io/api/core/v1"
9+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
10+
"sigs.k8s.io/yaml"
11+
12+
"github.com/openshift/installer/pkg/asset"
13+
"github.com/openshift/installer/pkg/asset/installconfig"
14+
"github.com/openshift/installer/pkg/types/baremetal"
15+
)
16+
17+
var (
18+
bmcVerifyCAConfigMapFileName = path.Join("manifests", "bmc-verify-ca-configmap.yaml")
19+
)
20+
21+
const (
22+
bmcVerifyCAConfigMapName = "bmc-verify-ca"
23+
bmcVerifyCAConfigMapNamespace = "openshift-machine-api"
24+
bmcVerifyCAConfigMapDataKey = "verify_ca.crt"
25+
)
26+
27+
// BMCVerifyCAConfigMap generates the bmc-verify-ca ConfigMap.
28+
type BMCVerifyCAConfigMap struct {
29+
ConfigMap *corev1.ConfigMap
30+
File *asset.File
31+
}
32+
33+
var _ asset.WritableAsset = (*BMCVerifyCAConfigMap)(nil)
34+
35+
// Name returns a human friendly name for the asset.
36+
func (*BMCVerifyCAConfigMap) Name() string {
37+
return "BMC Verify CA ConfigMap"
38+
}
39+
40+
// Dependencies returns all of the dependencies directly needed to generate
41+
// the asset.
42+
func (*BMCVerifyCAConfigMap) Dependencies() []asset.Asset {
43+
return []asset.Asset{
44+
&installconfig.InstallConfig{},
45+
}
46+
}
47+
48+
// Generate generates the BMC Verify CA ConfigMap.
49+
func (bvc *BMCVerifyCAConfigMap) Generate(_ context.Context, dependencies asset.Parents) error {
50+
installConfig := &installconfig.InstallConfig{}
51+
dependencies.Get(installConfig)
52+
53+
// Only generate the ConfigMap for baremetal platform with BMCVerifyCA configured
54+
if installConfig.Config.Platform.Name() != baremetal.Name {
55+
return nil
56+
}
57+
58+
if installConfig.Config.Platform.BareMetal == nil || installConfig.Config.Platform.BareMetal.BMCVerifyCA == "" {
59+
return nil
60+
}
61+
62+
cm := &corev1.ConfigMap{
63+
TypeMeta: metav1.TypeMeta{
64+
APIVersion: corev1.SchemeGroupVersion.String(),
65+
Kind: "ConfigMap",
66+
},
67+
ObjectMeta: metav1.ObjectMeta{
68+
Namespace: bmcVerifyCAConfigMapNamespace,
69+
Name: bmcVerifyCAConfigMapName,
70+
},
71+
Data: map[string]string{
72+
bmcVerifyCAConfigMapDataKey: installConfig.Config.Platform.BareMetal.BMCVerifyCA,
73+
},
74+
}
75+
76+
cmData, err := yaml.Marshal(cm)
77+
if err != nil {
78+
return errors.Wrapf(err, "failed to create %s manifest", bvc.Name())
79+
}
80+
bvc.ConfigMap = cm
81+
bvc.File = &asset.File{
82+
Filename: bmcVerifyCAConfigMapFileName,
83+
Data: cmData,
84+
}
85+
return nil
86+
}
87+
88+
// Files returns the files generated by the asset.
89+
func (bvc *BMCVerifyCAConfigMap) Files() []*asset.File {
90+
if bvc.File != nil {
91+
return []*asset.File{bvc.File}
92+
}
93+
return []*asset.File{}
94+
}
95+
96+
// Load loads the already-rendered files back from disk.
97+
func (bvc *BMCVerifyCAConfigMap) Load(f asset.FileFetcher) (bool, error) {
98+
return false, nil
99+
}

0 commit comments

Comments
 (0)