Skip to content

Commit c53de55

Browse files
Merge pull request #943 from ironcladlou/cloudprovider
Add a `config.openshift.io/Infrastructure` instance to the cluster
2 parents 761e172 + 696475e commit c53de55

File tree

17 files changed

+1535
-59
lines changed

17 files changed

+1535
-59
lines changed

Gopkg.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ ignored = [
8282

8383
[[constraint]]
8484
name = "github.com/openshift/api"
85-
revision = "8241b16bb46fe9bd7aebbbce92d7af84fb71be7f"
85+
revision = "aab033bae2a129607f4fb277c3777b2eabb08601"
8686

8787
[[constraint]]
8888
name = "github.com/openshift/client-go"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: apiextensions.k8s.io/v1beta1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
name: infrastructures.config.openshift.io
5+
spec:
6+
group: config.openshift.io
7+
names:
8+
kind: Infrastructure
9+
listKind: InfrastructureList
10+
plural: infrastructures
11+
singular: infrastructure
12+
scope: Cluster
13+
versions:
14+
- name: v1
15+
served: true
16+
storage: true

pkg/asset/manifests/infrastructure.go

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
package manifests
2+
3+
import (
4+
"path/filepath"
5+
6+
"github.com/ghodss/yaml"
7+
"github.com/pkg/errors"
8+
9+
"github.com/openshift/installer/pkg/asset"
10+
"github.com/openshift/installer/pkg/asset/installconfig"
11+
"github.com/openshift/installer/pkg/asset/templates/content/openshift"
12+
13+
configv1 "github.com/openshift/api/config/v1"
14+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
15+
16+
"github.com/openshift/installer/pkg/types/aws"
17+
"github.com/openshift/installer/pkg/types/libvirt"
18+
"github.com/openshift/installer/pkg/types/none"
19+
"github.com/openshift/installer/pkg/types/openstack"
20+
)
21+
22+
var (
23+
infraCrdFilename = filepath.Join(manifestDir, "cluster-infrastructure-01-crd.yaml")
24+
infraCfgFilename = filepath.Join(manifestDir, "cluster-infrastructure-02-config.yml")
25+
)
26+
27+
// Infrastructure generates the cluster-infrastructure-*.yml files.
28+
type Infrastructure struct {
29+
FileList []*asset.File
30+
}
31+
32+
var _ asset.WritableAsset = (*Infrastructure)(nil)
33+
34+
// Name returns a human friendly name for the asset.
35+
func (*Infrastructure) Name() string {
36+
return "Infrastructure Config"
37+
}
38+
39+
// Dependencies returns all of the dependencies directly needed to generate
40+
// the asset.
41+
func (*Infrastructure) Dependencies() []asset.Asset {
42+
return []asset.Asset{
43+
&installconfig.InstallConfig{},
44+
&openshift.InfrastructureCRD{},
45+
}
46+
}
47+
48+
// Generate generates the Infrastructure config and its CRD.
49+
func (i *Infrastructure) Generate(dependencies asset.Parents) error {
50+
installConfig := &installconfig.InstallConfig{}
51+
infra := &openshift.InfrastructureCRD{}
52+
dependencies.Get(installConfig, infra)
53+
54+
var platform configv1.PlatformType
55+
switch installConfig.Config.Platform.Name() {
56+
case aws.Name:
57+
platform = configv1.AWSPlatform
58+
case none.Name:
59+
platform = configv1.NonePlatform
60+
case libvirt.Name:
61+
platform = configv1.LibvirtPlatform
62+
case openstack.Name:
63+
platform = configv1.OpenStackPlatform
64+
default:
65+
platform = configv1.NonePlatform
66+
}
67+
68+
config := &configv1.Infrastructure{
69+
TypeMeta: metav1.TypeMeta{
70+
APIVersion: configv1.SchemeGroupVersion.String(),
71+
Kind: "Infrastructure",
72+
},
73+
ObjectMeta: metav1.ObjectMeta{
74+
Name: "cluster",
75+
// not namespaced
76+
},
77+
Status: configv1.InfrastructureStatus{
78+
Platform: platform,
79+
},
80+
}
81+
82+
configData, err := yaml.Marshal(config)
83+
if err != nil {
84+
return errors.Wrapf(err, "failed to marshal config: %#v", config)
85+
}
86+
87+
i.FileList = []*asset.File{
88+
{
89+
Filename: infraCrdFilename,
90+
Data: []byte(infra.Files()[0].Data),
91+
},
92+
{
93+
Filename: infraCfgFilename,
94+
Data: configData,
95+
},
96+
}
97+
98+
return nil
99+
}
100+
101+
// Files returns the files generated by the asset.
102+
func (i *Infrastructure) Files() []*asset.File {
103+
return i.FileList
104+
}
105+
106+
// Load returns false since this asset is not written to disk by the installer.
107+
func (i *Infrastructure) Load(f asset.FileFetcher) (bool, error) {
108+
return false, nil
109+
}

pkg/asset/manifests/operators.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ func (m *Manifests) Dependencies() []asset.Asset {
5555
&installconfig.InstallConfig{},
5656
&Ingress{},
5757
&DNS{},
58+
&Infrastructure{},
5859
&Networking{},
5960
&tls.RootCA{},
6061
&tls.EtcdCA{},
@@ -88,8 +89,9 @@ func (m *Manifests) Generate(dependencies asset.Parents) error {
8889
ingress := &Ingress{}
8990
dns := &DNS{}
9091
network := &Networking{}
92+
infra := &Infrastructure{}
9193
installConfig := &installconfig.InstallConfig{}
92-
dependencies.Get(installConfig, ingress, dns, network)
94+
dependencies.Get(installConfig, ingress, dns, network, infra)
9395

9496
// mao go to kube-system config map
9597
m.KubeSysConfig = configMap("kube-system", "cluster-config-v1", genericData{
@@ -111,6 +113,7 @@ func (m *Manifests) Generate(dependencies asset.Parents) error {
111113
m.FileList = append(m.FileList, ingress.Files()...)
112114
m.FileList = append(m.FileList, dns.Files()...)
113115
m.FileList = append(m.FileList, network.Files()...)
116+
m.FileList = append(m.FileList, infra.Files()...)
114117

115118
return nil
116119
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package openshift
2+
3+
import (
4+
"os"
5+
"path/filepath"
6+
7+
"github.com/openshift/installer/pkg/asset"
8+
"github.com/openshift/installer/pkg/asset/templates/content"
9+
)
10+
11+
const (
12+
infraCRDfilename = "cluster-infrastructure-crd.yaml"
13+
)
14+
15+
var _ asset.WritableAsset = (*InfrastructureCRD)(nil)
16+
17+
// InfrastructureCRD is the custom resource definition for the openshift/api
18+
// Infrastructure type.
19+
type InfrastructureCRD struct {
20+
fileName string
21+
FileList []*asset.File
22+
}
23+
24+
// Dependencies returns all of the dependencies directly needed by the asset
25+
func (t *InfrastructureCRD) Dependencies() []asset.Asset {
26+
return []asset.Asset{}
27+
}
28+
29+
// Name returns the human-friendly name of the asset.
30+
func (t *InfrastructureCRD) Name() string {
31+
return "Infrastructure"
32+
}
33+
34+
// Generate generates the actual files by this asset
35+
func (t *InfrastructureCRD) Generate(parents asset.Parents) error {
36+
t.fileName = infraCRDfilename
37+
data, err := content.GetOpenshiftTemplate(t.fileName)
38+
if err != nil {
39+
return err
40+
}
41+
t.FileList = []*asset.File{
42+
{
43+
Filename: filepath.Join(content.TemplateDir, t.fileName),
44+
Data: []byte(data),
45+
},
46+
}
47+
return nil
48+
}
49+
50+
// Files returns the files generated by the asset.
51+
func (t *InfrastructureCRD) Files() []*asset.File {
52+
return t.FileList
53+
}
54+
55+
// Load returns the asset from disk.
56+
func (t *InfrastructureCRD) Load(f asset.FileFetcher) (bool, error) {
57+
file, err := f.FetchByName(filepath.Join(content.TemplateDir, infraCRDfilename))
58+
if err != nil {
59+
if os.IsNotExist(err) {
60+
return false, nil
61+
}
62+
return false, err
63+
}
64+
t.FileList = []*asset.File{file}
65+
return true, nil
66+
}

pkg/asset/templates/templates.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func (m *Templates) Dependencies() []asset.Asset {
4141
&openshift.CloudCredsSecret{},
4242
&openshift.KubeadminPasswordSecret{},
4343
&openshift.RoleCloudCredsSecretReader{},
44+
&openshift.InfrastructureCRD{},
4445
}
4546
}
4647

@@ -65,6 +66,7 @@ func (m *Templates) Generate(dependencies asset.Parents) error {
6566
cloudCredsSecret := &openshift.CloudCredsSecret{}
6667
kubeadminPasswordSecret := &openshift.KubeadminPasswordSecret{}
6768
roleCloudCredsSecretReader := &openshift.RoleCloudCredsSecretReader{}
69+
infrastructure := &openshift.InfrastructureCRD{}
6870

6971
dependencies.Get(
7072
kubeCloudConfig,
@@ -84,7 +86,8 @@ func (m *Templates) Generate(dependencies asset.Parents) error {
8486
bindingDiscovery,
8587
cloudCredsSecret,
8688
kubeadminPasswordSecret,
87-
roleCloudCredsSecretReader)
89+
roleCloudCredsSecretReader,
90+
infrastructure)
8891

8992
m.FileList = []*asset.File{}
9093
m.FileList = append(m.FileList, kubeCloudConfig.Files()...)
@@ -106,6 +109,7 @@ func (m *Templates) Generate(dependencies asset.Parents) error {
106109
m.FileList = append(m.FileList, cloudCredsSecret.Files()...)
107110
m.FileList = append(m.FileList, kubeadminPasswordSecret.Files()...)
108111
m.FileList = append(m.FileList, roleCloudCredsSecretReader.Files()...)
112+
m.FileList = append(m.FileList, infrastructure.Files()...)
109113

110114
return nil
111115
}

vendor/github.com/openshift/api/config/v1/register.go

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/openshift/api/config/v1/types.go

Lines changed: 8 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/openshift/api/config/v1/types_authentication.go

Lines changed: 33 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)