-
Notifications
You must be signed in to change notification settings - Fork 1.5k
pkg/asset: Add asset for ingress config #717
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
openshift-merge-robot
merged 2 commits into
openshift:master
from
Miciah:pkg-slash-asset-add-asset-for-ingress-config
Nov 27, 2018
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.