Skip to content
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

Add --publish-status-address to 2.x #1509

Merged
merged 3 commits into from
Jul 7, 2021
Merged
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
16 changes: 14 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Table of Contents

- [2.0.0-alpha.2](#200-alpha2---tbd)
- [2.0.0-alpha.3](#200-alpha3---tbd)
- [2.0.0-alpha.2](#200-alpha2---20210707)
rainest marked this conversation as resolved.
Show resolved Hide resolved
- [2.0.0-alpha.1](#200-alpha1---20210527)
- [1.3.1](#131---20210603)
- [1.3.0](#130---20210527)
Expand Down Expand Up @@ -31,7 +32,17 @@
- [0.0.5](#005---20180602)
- [0.0.4 and prior](#004-and-prior)

## [2.0.0-alpha.2] - TBD
## [2.0.0-alpha.3] - TBD

#### Added

- Implemented Ingress status updates in 2.x.
[#1451](https:/Kong/kubernetes-ingress-controller/pull/1451)
- Added `--publish-status-address` and `--publish-service` flags to 2.x.
[#1451](https:/Kong/kubernetes-ingress-controller/pull/1451)
[#1509](https:/Kong/kubernetes-ingress-controller/pull/1509)

## [2.0.0-alpha.2] - 2021/07/07

#### Fixed

Expand Down Expand Up @@ -1135,6 +1146,7 @@ Please read the changelog and test in your environment.
- The initial versions were rapildy iterated to deliver
a working ingress controller.

[2.0.0-alpha.3]: https:/kong/kubernetes-ingress-controller/compare/2.0.0-alpha.2...2.0.0-alpha.3
[2.0.0-alpha.2]: https:/kong/kubernetes-ingress-controller/compare/2.0.0-alpha.1...2.0.0-alpha.2
[2.0.0-alpha.1]: https:/kong/kubernetes-ingress-controller/compare/1.2.0...2.0.0-alpha.1
[1.3.1]: https:/kong/kubernetes-ingress-controller/compare/1.3.0...1.3.1
rainest marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
14 changes: 11 additions & 3 deletions railgun/internal/ctrlutils/ingress-status.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ const (
)

// PullConfigUpdate is a dedicated function that process ingress/customer resource status update after configuration is updated within kong.
func PullConfigUpdate(ctx context.Context, kongConfig sendconfig.Kong, log logr.Logger, kubeConfig *rest.Config, publishService string) {
ips, hostname, err := RunningAddresses(ctx, kubeConfig, publishService)
func PullConfigUpdate(ctx context.Context, kongConfig sendconfig.Kong, log logr.Logger, kubeConfig *rest.Config,
publishService string, publishAddresses []string) {
ips, hostname, err := RunningAddresses(ctx, kubeConfig, publishService, publishAddresses)
if err != nil {
log.Error(err, "failed to determine kong proxy external ips/hostnames.")
return
Expand Down Expand Up @@ -317,8 +318,13 @@ func UpdateKnativeIngress(ctx context.Context, logger logr.Logger, svc file.FSer
}

// RunningAddresses retrieve cluster loader balance IP or hostaddress using networking
func RunningAddresses(ctx context.Context, kubeCfg *rest.Config, publishService string) ([]string, string, error) {
func RunningAddresses(ctx context.Context, kubeCfg *rest.Config, publishService string,
publishAddresses []string) ([]string, string, error) {
addrs := []string{}
if len(publishAddresses) > 0 {
addrs = append(addrs, publishAddresses...)
return addrs, "", nil
}
namespace, name, err := util.ParseNameNS(publishService)
if err != nil {
return nil, "", fmt.Errorf("unable to retrieve service for status: %w", err)
Expand All @@ -333,6 +339,7 @@ func RunningAddresses(ctx context.Context, kubeCfg *rest.Config, publishService

clusterDomain := network.GetClusterDomainName()
hostname := fmt.Sprintf("%s.%s.svc.%s", name, namespace, clusterDomain)

switch svc.Spec.Type {
case apiv1.ServiceTypeLoadBalancer:
for _, ip := range svc.Status.LoadBalancer.Ingress {
Expand All @@ -342,6 +349,7 @@ func RunningAddresses(ctx context.Context, kubeCfg *rest.Config, publishService
addrs = append(addrs, ip.IP)
}
}

rainest marked this conversation as resolved.
Show resolved Hide resolved
addrs = append(addrs, svc.Spec.ExternalIPs...)
return addrs, hostname, nil
default:
Expand Down
3 changes: 2 additions & 1 deletion railgun/manager/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ func Run(ctx context.Context, c *config.Config) error {
filterTags = c.FilterTags
}

// configure the kong client
kongConfig := sendconfig.Kong{
URL: c.KongAdminURL,
FilterTags: filterTags,
Expand Down Expand Up @@ -166,7 +167,7 @@ func Run(ctx context.Context, c *config.Config) error {
return err
}

go ctrlutils.PullConfigUpdate(ctx, kongConfig, logger, kubeconfig, c.PublishService)
go ctrlutils.PullConfigUpdate(ctx, kongConfig, logger, kubeconfig, c.PublishService, c.PublishStatusAddress)

alwaysEnabled := util.EnablementStatusEnabled
controllers := []ControllerDef{
Expand Down
7 changes: 5 additions & 2 deletions railgun/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ type Config struct {
WatchNamespace string

// Ingress status
PublishService string
PublishService string
PublishStatusAddress []string

// Kubernetes API toggling
IngressExtV1beta1Enabled util.EnablementStatus
Expand Down Expand Up @@ -117,7 +118,6 @@ func (c *Config) FlagSet() *pflag.FlagSet {
flagSet.StringVar(&c.APIServerHost, "apiserver-host", "", `The Kubernetes API server URL. If not set, the controller will use cluster config discovery.`)
flagSet.StringVar(&c.MetricsAddr, "metrics-bind-address", fmt.Sprintf(":%v", MetricsPort), "The address the metric endpoint binds to.")
flagSet.StringVar(&c.ProbeAddr, "health-probe-bind-address", fmt.Sprintf(":%v", HealthzPort), "The address the probe endpoint binds to.")
// the hardcod only for development debug purpose
flagSet.StringVar(&c.KongAdminURL, "kong-admin-url", "http://localhost:8001", `The Kong Admin URL to connect to in the format "protocol://address:port".`)
flagSet.Float32Var(&c.ProxySyncSeconds, "sync-rate-limit", proxy.DefaultSyncSeconds,
fmt.Sprintf(
Expand Down Expand Up @@ -150,6 +150,9 @@ func (c *Config) FlagSet() *pflag.FlagSet {
// Ingress status
flagSet.StringVar(&c.PublishService, "publish-service", "", `Service fronting Ingress resources in "namespace/name"
format. The controller will update Ingress status information with this Service's endpoints.`)
flagSet.StringSliceVar(&c.PublishStatusAddress, "publish-status-address", []string{}, `User-provided addresses in
comma-separated string format, for use in lieu of "publish-service" when that Service lacks useful address
information (for example, in bare-metal environments).`)

// Kubernetes API toggling
flagSet.enablementStatusVar(&c.IngressNetV1Enabled, "controller-ingress-networkingv1", util.EnablementStatusEnabled, "Enable or disable the Ingress controller (using API version networking.k8s.io/v1)."+onOffUsage)
Expand Down