Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 115 additions & 0 deletions pkg/asset/manifests/coredns.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package manifests

import (
"context"
"fmt"
"path"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/yaml"

operatorv1 "github.com/openshift/api/operator/v1"
"github.com/openshift/installer/pkg/asset"
"github.com/openshift/installer/pkg/asset/installconfig"
awstypes "github.com/openshift/installer/pkg/types/aws"
"github.com/openshift/installer/pkg/types/dns"
)

var (
coreDNSCfgFilename = path.Join(manifestDir, "coredns-02-config.yml")
)

// CoreDNS generates the files to configure CoreDNS component, which provides a name resolution service
// for pods and services in the cluster.
type CoreDNS struct {
FileList []*asset.File
}

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

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

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

// Generate generates the CoreDNS config and its CRD.
func (d *CoreDNS) Generate(ctx context.Context, dependencies asset.Parents) error {
installConfig := &installconfig.InstallConfig{}
dependencies.Get(installConfig)

var controllerConfig *operatorv1.DNS

switch installConfig.Config.Platform.Name() {
case awstypes.Name:
// We don't configure coreDNS here when UserProvisionedDNS is enabled
if installConfig.Config.AWS.UserProvisionedDNS == dns.UserProvisionedDNSEnabled {
Comment thread
tthvo marked this conversation as resolved.
return nil
}

if installConfig.Config.AWS.IPFamily.DualStackEnabled() {
// By default, in dualstack subnets, the resolver config file on instances only define the IPv4 DNS resolver.
// For dualstack, we need to also allow the IPv6 DNS resolver "fd00:ec2::253"
// See: https://docs.aws.amazon.com/whitepapers/latest/ipv6-on-aws/supporting-amazon-vpc-services.html#route-53-dns-resolver
controllerConfig = &operatorv1.DNS{
TypeMeta: metav1.TypeMeta{
APIVersion: operatorv1.SchemeGroupVersion.String(),
Kind: "DNS",
},
ObjectMeta: metav1.ObjectMeta{
Name: "default",
// not namespaced
},
Spec: operatorv1.DNSSpec{
UpstreamResolvers: operatorv1.UpstreamResolvers{
Policy: operatorv1.SequentialForwardingPolicy,
Upstreams: []operatorv1.Upstream{
{
Type: operatorv1.SystemResolveConfType,
},
{

Type: operatorv1.NetworkResolverType,
Address: "fd00:ec2::253",
},
},
},
},
}
}
default:
}

if controllerConfig != nil {
configData, err := yaml.Marshal(controllerConfig)
if err != nil {
return fmt.Errorf("failed to create %s manifests from InstallConfig: %w", d.Name(), err)
}

d.FileList = []*asset.File{
{
Filename: coreDNSCfgFilename,
Data: configData,
},
}
}

return nil
}

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

// Load loads the already-rendered files back from disk.
func (d *CoreDNS) Load(f asset.FileFetcher) (bool, error) {
return false, nil
}
5 changes: 4 additions & 1 deletion pkg/asset/manifests/operators.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func (m *Manifests) Dependencies() []asset.Asset {
&manifests.MCO{},
&Ingress{},
&DNS{},
&CoreDNS{},
&Infrastructure{},
&Networking{},
&Proxy{},
Expand Down Expand Up @@ -97,6 +98,7 @@ func (m *Manifests) Dependencies() []asset.Asset {
func (m *Manifests) Generate(_ context.Context, dependencies asset.Parents) error {
ingress := &Ingress{}
dns := &DNS{}
coreDNS := &CoreDNS{}
network := &Networking{}
infra := &Infrastructure{}
installConfig := &installconfig.InstallConfig{}
Expand All @@ -108,7 +110,7 @@ func (m *Manifests) Generate(_ context.Context, dependencies asset.Parents) erro
mcoCfgTemplate := &manifests.MCO{}
bmcVerifyCAConfigMap := &BMCVerifyCAConfigMap{}

dependencies.Get(installConfig, ingress, dns, network, infra, proxy, scheduler, imageContentSourcePolicy, imageDigestMirrorSet, clusterCSIDriverConfig, mcoCfgTemplate, bmcVerifyCAConfigMap)
dependencies.Get(installConfig, ingress, dns, coreDNS, network, infra, proxy, scheduler, imageContentSourcePolicy, imageDigestMirrorSet, clusterCSIDriverConfig, mcoCfgTemplate, bmcVerifyCAConfigMap)

redactedConfig, err := redactedInstallConfig(*installConfig.Config)
if err != nil {
Expand Down Expand Up @@ -139,6 +141,7 @@ func (m *Manifests) Generate(_ context.Context, dependencies asset.Parents) erro

m.FileList = append(m.FileList, ingress.Files()...)
m.FileList = append(m.FileList, dns.Files()...)
m.FileList = append(m.FileList, coreDNS.Files()...)
m.FileList = append(m.FileList, network.Files()...)
m.FileList = append(m.FileList, infra.Files()...)
m.FileList = append(m.FileList, proxy.Files()...)
Expand Down