-
Notifications
You must be signed in to change notification settings - Fork 223
Manage routing wildcard domain #59
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
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.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,9 +2,13 @@ package main | |
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "runtime" | ||
| "strings" | ||
| "time" | ||
|
|
||
| "github.com/openshift/cluster-ingress-operator/pkg/dns" | ||
| awsdns "github.com/openshift/cluster-ingress-operator/pkg/dns/aws" | ||
| "github.com/openshift/cluster-ingress-operator/pkg/manifests" | ||
| stub "github.com/openshift/cluster-ingress-operator/pkg/stub" | ||
| "github.com/openshift/cluster-ingress-operator/pkg/util" | ||
|
|
@@ -18,6 +22,8 @@ import ( | |
|
|
||
| "github.com/sirupsen/logrus" | ||
|
|
||
| corev1 "k8s.io/api/core/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" | ||
| ) | ||
|
|
||
|
|
@@ -38,34 +44,75 @@ func main() { | |
| if err != nil { | ||
| logrus.Fatalf("Failed to get watch namespace: %v", err) | ||
| } | ||
| kubeClient := k8sclient.GetKubeClient() | ||
|
|
||
| ic, err := util.GetInstallConfig(kubeClient) | ||
| handler, err := createHandler(namespace) | ||
| if err != nil { | ||
| logrus.Fatalf("could't get installconfig: %v", err) | ||
| } | ||
|
|
||
| cvoClient, err := cvoclientset.NewForConfig(k8sclient.GetKubeConfig()) | ||
| if err != nil { | ||
| logrus.Fatalf("Failed to get cvoClient: %v", err) | ||
| } | ||
|
|
||
| handler := &stub.Handler{ | ||
| CvoClient: cvoClient, | ||
| InstallConfig: ic, | ||
| Namespace: namespace, | ||
| ManifestFactory: manifests.NewFactory(), | ||
| logrus.Fatalf("couldn't create handler: %v", err) | ||
| } | ||
|
|
||
| if err := handler.EnsureDefaultClusterIngress(); err != nil { | ||
| logrus.Fatalf("failed to ensure default cluster ingress: %v", err) | ||
| } | ||
|
|
||
| resyncPeriod := 10 * time.Minute | ||
| logrus.Infof("Watching %s, %s, %s, %d", resource, kind, namespace, resyncPeriod) | ||
| sdk.Watch(resource, kind, namespace, resyncPeriod) | ||
| // TODO Use a named constant for the router's namespace or get the | ||
| // namespace from config. | ||
| sdk.Watch("apps/v1", "DaemonSet", "openshift-ingress", resyncPeriod) | ||
| sdk.Watch("v1", "Service", "openshift-ingress", resyncPeriod) | ||
| sdk.Handle(handler) | ||
| sdk.Run(context.TODO()) | ||
| } | ||
|
|
||
| func createHandler(namespace string) (*stub.Handler, error) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be moved to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I almost didn't even refactor this -- I think we have more to think about here in terms of setup. Okay to revisit after the sdk upgrade?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, it's only a suggestion. |
||
| cvoClient, err := cvoclientset.NewForConfig(k8sclient.GetKubeConfig()) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to create CVO client: %v", err) | ||
| } | ||
|
|
||
| ic, err := util.GetInstallConfig(k8sclient.GetKubeClient()) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to get installconfig: %v", err) | ||
| } | ||
|
|
||
| var dnsManager dns.Manager | ||
| switch { | ||
| case ic.Platform.AWS != nil: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could have an
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, right, sorry. Never mind! |
||
| awsCreds := &corev1.Secret{ | ||
| TypeMeta: metav1.TypeMeta{ | ||
| APIVersion: "v1", | ||
| Kind: "Secret", | ||
| }, | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: "aws-creds", | ||
| Namespace: metav1.NamespaceSystem, | ||
| }, | ||
| } | ||
| err := sdk.Get(awsCreds) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to get aws creds from %s/%s: %v", awsCreds.Namespace, awsCreds.Name, err) | ||
| } | ||
| manager, err := awsdns.NewManager(awsdns.Config{ | ||
| AccessID: string(awsCreds.Data["aws_access_key_id"]), | ||
| AccessKey: string(awsCreds.Data["aws_secret_access_key"]), | ||
| Region: ic.Platform.AWS.Region, | ||
| BaseDomain: strings.TrimSuffix(ic.BaseDomain, ".") + ".", | ||
| ClusterID: ic.ClusterID, | ||
| }) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to create AWS DNS manager: %v", err) | ||
| } | ||
| dnsManager = manager | ||
| default: | ||
| dnsManager = &dns.NoopManager{} | ||
| } | ||
|
|
||
| return &stub.Handler{ | ||
| InstallConfig: ic, | ||
| CvoClient: cvoClient, | ||
| Namespace: namespace, | ||
| ManifestFactory: manifests.NewFactory(), | ||
| DNSManager: dnsManager, | ||
| }, nil | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # Binds the aws-creds-secret-reader role to the operator Service Account. | ||
| kind: RoleBinding | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| metadata: | ||
| name: ingress-operator-aws-creds-secret-reader | ||
| namespace: kube-system | ||
| subjects: | ||
| - kind: ServiceAccount | ||
| name: ingress-operator | ||
| namespace: openshift-ingress-operator | ||
| roleRef: | ||
| kind: Role | ||
| apiGroup: rbac.authorization.k8s.io | ||
| name: aws-creds-secret-reader |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should check
err.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed