Skip to content

Commit

Permalink
Merge pull request #717 from Miciah/pkg-slash-asset-add-asset-for-ing…
Browse files Browse the repository at this point in the history
…ress-config

pkg/asset: Add asset for ingress config
  • Loading branch information
openshift-merge-robot authored Nov 27, 2018
2 parents 64af808 + 63a161c commit a4b758d
Show file tree
Hide file tree
Showing 26 changed files with 3,629 additions and 1 deletion.
9 changes: 9 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,7 @@ ignored = ["github.com/openshift/installer/tests*"]
[[constraint]]
name = "github.com/gophercloud/utils"
revision = "34f5991525d116b3832e0d9409492274f1c06bda"

[[constraint]]
branch = "master"
name = "github.com/openshift/api"
16 changes: 16 additions & 0 deletions data/data/manifests/bootkube/cluster-ingress-01-crd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: ingresses.config.openshift.io
spec:
group: config.openshift.io
names:
kind: Ingress
listKind: IngressList
plural: ingresses
singular: ingress
scope: Cluster
versions:
- name: v1
served: true
storage: true
122 changes: 122 additions & 0 deletions pkg/asset/manifests/ingress.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package manifests

import (
"fmt"
"os"
"path/filepath"

"github.com/ghodss/yaml"
"github.com/pkg/errors"

"github.com/openshift/installer/pkg/asset"
"github.com/openshift/installer/pkg/asset/installconfig"
"github.com/openshift/installer/pkg/asset/templates/content"

configv1 "github.com/openshift/api/config/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

var (
ingCrdFilename = "cluster-ingress-01-crd.yaml"
ingCfgFilename = filepath.Join(manifestDir, "cluster-ingress-02-config.yml")
)

// Ingress generates the cluster-ingress-*.yml files.
type Ingress struct {
config *configv1.Ingress
FileList []*asset.File
}

var _ asset.WritableAsset = (*Ingress)(nil)

// Name returns a human friendly name for the asset.
func (*Ingress) Name() string {
return "Ingress Config"
}

// Dependencies returns all of the dependencies directly needed to generate
// the asset.
func (*Ingress) Dependencies() []asset.Asset {
return []asset.Asset{
&installconfig.InstallConfig{},
}
}

// Generate generates the ingress config and its CRD.
func (ing *Ingress) Generate(dependencies asset.Parents) error {
installConfig := &installconfig.InstallConfig{}
dependencies.Get(installConfig)

ing.config = &configv1.Ingress{
TypeMeta: metav1.TypeMeta{
APIVersion: configv1.SchemeGroupVersion.String(),
Kind: "Ingress",
},
ObjectMeta: metav1.ObjectMeta{
Name: "default",
// not namespaced
},
Spec: configv1.IngressSpec{
Domain: fmt.Sprintf("apps.%s.%s", installConfig.Config.ObjectMeta.Name, installConfig.Config.BaseDomain),
},
}

configData, err := yaml.Marshal(ing.config)
if err != nil {
return errors.Wrapf(err, "failed to create %s manifests from InstallConfig", ing.Name())
}

crdData, err := content.GetBootkubeTemplate(ingCrdFilename)
if err != nil {
return err
}

ing.FileList = []*asset.File{
{
Filename: filepath.Join(content.TemplateDir, ingCrdFilename),
Data: []byte(crdData),
},
{
Filename: ingCfgFilename,
Data: configData,
},
}

return nil
}

// Files returns the files generated by the asset.
func (ing *Ingress) Files() []*asset.File {
return ing.FileList
}

// Load loads the already-rendered files back from disk.
func (ing *Ingress) Load(f asset.FileFetcher) (bool, error) {
crdFile, err := f.FetchByName(ingCrdFilename)
if err != nil {
if os.IsNotExist(err) {
return false, nil
}
return false, err
}

cfgFile, err := f.FetchByName(ingCfgFilename)
if err != nil {
if os.IsNotExist(err) {
return false, nil
}

return false, err
}

ingressConfig := &configv1.Ingress{}
if err := yaml.Unmarshal(cfgFile.Data, ingressConfig); err != nil {
return false, errors.Wrapf(err, "failed to unmarshal %s", ingCfgFilename)
}

fileList := []*asset.File{crdFile, cfgFile}

ing.FileList, ing.config = fileList, ingressConfig

return true, nil
}
5 changes: 4 additions & 1 deletion pkg/asset/manifests/operators.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func (m *Manifests) Name() string {
func (m *Manifests) Dependencies() []asset.Asset {
return []asset.Asset{
&installconfig.InstallConfig{},
&Ingress{},
&Networking{},
&tls.RootCA{},
&tls.EtcdCA{},
Expand Down Expand Up @@ -85,9 +86,10 @@ func (m *Manifests) Dependencies() []asset.Asset {

// Generate generates the respective operator config.yml files
func (m *Manifests) Generate(dependencies asset.Parents) error {
ingress := &Ingress{}
network := &Networking{}
installConfig := &installconfig.InstallConfig{}
dependencies.Get(installConfig, network)
dependencies.Get(installConfig, ingress, network)

// mao go to kube-system config map
m.KubeSysConfig = configMap("kube-system", "cluster-config-v1", genericData{
Expand All @@ -106,6 +108,7 @@ func (m *Manifests) Generate(dependencies asset.Parents) error {
}
m.FileList = append(m.FileList, m.generateBootKubeManifests(dependencies)...)

m.FileList = append(m.FileList, ingress.Files()...)
m.FileList = append(m.FileList, network.Files()...)

return nil
Expand Down
Loading

0 comments on commit a4b758d

Please sign in to comment.