-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #717 from Miciah/pkg-slash-asset-add-asset-for-ing…
…ress-config pkg/asset: Add asset for ingress config
- Loading branch information
Showing
26 changed files
with
3,629 additions
and
1 deletion.
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 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 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 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 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.