Skip to content

Commit 8b7d5c6

Browse files
Merge pull request openshift#8514 from mresvanis/add-image-based-config-iso
MGMT-17842: Add image-based installer create config ISO
2 parents ca59986 + 6b4bcf7 commit 8b7d5c6

21 files changed

+2648
-30
lines changed

cmd/openshift-install/imagebased.go

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@ package main
33
import (
44
"context"
55

6-
"github.com/sirupsen/logrus"
76
"github.com/spf13/cobra"
87

98
"github.com/openshift/installer/pkg/asset"
9+
"github.com/openshift/installer/pkg/asset/imagebased/configimage"
1010
"github.com/openshift/installer/pkg/asset/imagebased/image"
11+
"github.com/openshift/installer/pkg/asset/kubeconfig"
12+
"github.com/openshift/installer/pkg/asset/password"
1113
)
1214

1315
func newImageBasedCmd(ctx context.Context) *cobra.Command {
1416
imagebasedCmd := &cobra.Command{
1517
Use: "image-based",
16-
Short: "Commands for supporting cluster installation using the Image-based installer",
18+
Short: "Commands for supporting cluster installation using the image-based installer",
1719
RunE: func(cmd *cobra.Command, args []string) error {
1820
return cmd.Help()
1921
},
@@ -48,9 +50,37 @@ var (
4850
},
4951
}
5052

53+
imageBasedConfigTemplateTarget = target{
54+
name: "Image-based Installer Config ISO Configuration Template",
55+
command: &cobra.Command{
56+
Use: "config-template",
57+
Short: "Generates a template of the Image-based Config ISO config manifest used by the image-based installer",
58+
Args: cobra.ExactArgs(0),
59+
},
60+
assets: []asset.WritableAsset{
61+
&configimage.ImageBasedConfig{},
62+
},
63+
}
64+
65+
imageBasedConfigImageTarget = target{
66+
name: "Image-based Installer Config ISO Image",
67+
command: &cobra.Command{
68+
Use: "config-image",
69+
Short: "Generates an ISO containing configuration files only",
70+
Args: cobra.ExactArgs(0),
71+
},
72+
assets: []asset.WritableAsset{
73+
&configimage.ConfigImage{},
74+
&kubeconfig.ImageBasedAdminClient{},
75+
&password.KubeadminPassword{},
76+
},
77+
}
78+
5179
imageBasedTargets = []target{
5280
imageBasedInstallationConfigTemplateTarget,
5381
imageBasedInstallationImageTarget,
82+
imageBasedConfigTemplateTarget,
83+
imageBasedConfigImageTarget,
5484
}
5585
)
5686

@@ -69,30 +99,5 @@ func newImageBasedCreateCmd(ctx context.Context) *cobra.Command {
6999
cmd.AddCommand(t.command)
70100
}
71101

72-
cmd.AddCommand(createConfigTemplateCmd())
73-
cmd.AddCommand(createConfigImageCmd())
74-
75102
return cmd
76103
}
77-
78-
func createConfigTemplateCmd() *cobra.Command {
79-
return &cobra.Command{
80-
Use: "config-template",
81-
Short: "Generates a template of the Image-based Config ISO config manifest used by the Image-based installer",
82-
Args: cobra.ExactArgs(0),
83-
Run: func(_ *cobra.Command, _ []string) {
84-
logrus.Info("Create config template command")
85-
},
86-
}
87-
}
88-
89-
func createConfigImageCmd() *cobra.Command {
90-
return &cobra.Command{
91-
Use: "config-image",
92-
Short: "Generates an ISO containing configuration files only",
93-
Args: cobra.ExactArgs(0),
94-
Run: func(_ *cobra.Command, _ []string) {
95-
logrus.Info("Create config image command")
96-
},
97-
}
98-
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ require (
128128
sigs.k8s.io/cluster-api-provider-vsphere v1.9.3
129129
sigs.k8s.io/controller-runtime v0.18.3
130130
sigs.k8s.io/controller-tools v0.12.0
131+
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd
131132
sigs.k8s.io/yaml v1.4.0
132133
)
133134

@@ -292,7 +293,6 @@ require (
292293
k8s.io/component-base v0.30.1 // indirect
293294
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect
294295
k8s.io/kubectl v0.30.1 // indirect
295-
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
296296
sigs.k8s.io/kustomize/api v0.16.0 // indirect
297297
sigs.k8s.io/kustomize/kyaml v0.16.0 // indirect
298298
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package configimage
2+
3+
import (
4+
"context"
5+
6+
"github.com/openshift/installer/pkg/asset"
7+
"github.com/openshift/installer/pkg/asset/tls"
8+
)
9+
10+
// ImageBasedKubeAPIServerCompleteCABundle is the asset the generates the kube-apiserver-complete-server-ca-bundle,
11+
// which contains all the certs that are valid to confirm the kube-apiserver identity and it also contains the
12+
// Ingress Operator CA certificate.
13+
type ImageBasedKubeAPIServerCompleteCABundle struct {
14+
tls.CertBundle
15+
}
16+
17+
var _ asset.Asset = (*ImageBasedKubeAPIServerCompleteCABundle)(nil)
18+
19+
// Dependencies returns the dependency of the cert bundle.
20+
func (a *ImageBasedKubeAPIServerCompleteCABundle) Dependencies() []asset.Asset {
21+
return []asset.Asset{
22+
&tls.KubeAPIServerLocalhostCABundle{},
23+
&tls.KubeAPIServerServiceNetworkCABundle{},
24+
&tls.KubeAPIServerLBCABundle{},
25+
&IngressOperatorCABundle{},
26+
}
27+
}
28+
29+
// Generate generates the cert bundle based on its dependencies.
30+
func (a *ImageBasedKubeAPIServerCompleteCABundle) Generate(ctx context.Context, deps asset.Parents) error {
31+
certs := []tls.CertInterface{}
32+
for _, asset := range a.Dependencies() {
33+
deps.Get(asset)
34+
certs = append(certs, asset.(tls.CertInterface))
35+
}
36+
return a.CertBundle.Generate(ctx, "kube-apiserver-complete-server-ca-bundle", certs...)
37+
}
38+
39+
// Name returns the human-friendly name of the asset.
40+
func (a *ImageBasedKubeAPIServerCompleteCABundle) Name() string {
41+
return "Certificate (kube-apiserver-complete-server-ca-bundle)"
42+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package configimage
2+
3+
import (
4+
"bytes"
5+
"context"
6+
"testing"
7+
8+
"github.com/stretchr/testify/assert"
9+
10+
"github.com/openshift/installer/pkg/asset"
11+
"github.com/openshift/installer/pkg/asset/tls"
12+
)
13+
14+
func TestCaBundle_Generate(t *testing.T) {
15+
expectedBundleRaw := bytes.Join([][]byte{
16+
lbCABundle().BundleRaw,
17+
localhostCABundle().BundleRaw,
18+
serviceNetworkCABundle().BundleRaw,
19+
ingressCABundle().BundleRaw,
20+
}, []byte{})
21+
22+
cases := []struct {
23+
name string
24+
dependencies []asset.Asset
25+
expected *tls.CertBundle
26+
}{
27+
{
28+
name: "valid dependencies",
29+
dependencies: []asset.Asset{
30+
lbCABundle(),
31+
localhostCABundle(),
32+
serviceNetworkCABundle(),
33+
ingressCABundle(),
34+
},
35+
expected: &tls.CertBundle{
36+
BundleRaw: expectedBundleRaw,
37+
FileList: []*asset.File{
38+
{
39+
Filename: "tls/kube-apiserver-complete-server-ca-bundle.crt",
40+
Data: expectedBundleRaw,
41+
},
42+
},
43+
},
44+
},
45+
}
46+
for _, tc := range cases {
47+
t.Run(tc.name, func(t *testing.T) {
48+
parents := asset.Parents{}
49+
parents.Add(tc.dependencies...)
50+
51+
asset := &ImageBasedKubeAPIServerCompleteCABundle{}
52+
err := asset.Generate(context.TODO(), parents)
53+
assert.NoError(t, err)
54+
assert.Equal(t, string(tc.expected.BundleRaw), string(asset.CertBundle.BundleRaw))
55+
assert.Equal(t, tc.expected.FileList, asset.CertBundle.FileList)
56+
})
57+
}
58+
}
59+
60+
func lbCABundle() *tls.KubeAPIServerLBCABundle {
61+
return &tls.KubeAPIServerLBCABundle{
62+
CertBundle: tls.CertBundle{
63+
BundleRaw: []byte(testCert),
64+
},
65+
}
66+
}
67+
68+
func localhostCABundle() *tls.KubeAPIServerLocalhostCABundle {
69+
return &tls.KubeAPIServerLocalhostCABundle{
70+
CertBundle: tls.CertBundle{
71+
BundleRaw: []byte(testCert),
72+
},
73+
}
74+
}
75+
76+
func serviceNetworkCABundle() *tls.KubeAPIServerServiceNetworkCABundle {
77+
return &tls.KubeAPIServerServiceNetworkCABundle{
78+
CertBundle: tls.CertBundle{
79+
BundleRaw: []byte(testCert),
80+
},
81+
}
82+
}
83+
84+
func ingressCABundle() *IngressOperatorCABundle {
85+
return &IngressOperatorCABundle{
86+
CertBundle: tls.CertBundle{
87+
BundleRaw: []byte(testCert),
88+
},
89+
}
90+
}

0 commit comments

Comments
 (0)