Skip to content

Commit 9897e85

Browse files
authored
Merge pull request #2089 from FabianKramm/main
fix: add ingress host automatically to certificate
2 parents 6c76649 + 5899184 commit 9897e85

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

pkg/server/cert/syncer.go

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import (
99
"sync"
1010
"time"
1111

12-
"github.com/loft-sh/vcluster/pkg/config"
1312
"github.com/loft-sh/vcluster/pkg/constants"
1413
"github.com/loft-sh/vcluster/pkg/controllers/resources/nodes/nodeservice"
14+
"github.com/loft-sh/vcluster/pkg/syncer/synccontext"
1515
"github.com/loft-sh/vcluster/pkg/util/translate"
1616
corev1 "k8s.io/api/core/v1"
1717
kerrors "k8s.io/apimachinery/pkg/api/errors"
@@ -33,27 +33,31 @@ type Syncer interface {
3333
dynamiccertificates.CertKeyContentProvider
3434
}
3535

36-
func NewSyncer(_ context.Context, currentNamespace string, currentNamespaceClient client.Client, options *config.VirtualClusterConfig) (Syncer, error) {
36+
func NewSyncer(ctx *synccontext.ControllerContext) (Syncer, error) {
3737
return &syncer{
38-
clusterDomain: options.Networking.Advanced.ClusterDomain,
38+
clusterDomain: ctx.Config.Networking.Advanced.ClusterDomain,
3939

40-
serverCaKey: options.VirtualClusterKubeConfig().ServerCAKey,
41-
serverCaCert: options.VirtualClusterKubeConfig().ServerCACert,
40+
ingressHost: ctx.Config.ControlPlane.Ingress.Host,
4241

43-
fakeKubeletIPs: options.Networking.Advanced.ProxyKubelets.ByIP,
42+
serverCaKey: ctx.Config.VirtualClusterKubeConfig().ServerCAKey,
43+
serverCaCert: ctx.Config.VirtualClusterKubeConfig().ServerCACert,
4444

45-
addSANs: options.ControlPlane.Proxy.ExtraSANs,
45+
fakeKubeletIPs: ctx.Config.Networking.Advanced.ProxyKubelets.ByIP,
46+
47+
addSANs: ctx.Config.ControlPlane.Proxy.ExtraSANs,
4648
listeners: []dynamiccertificates.Listener{},
4749

48-
serviceName: options.WorkloadService,
49-
currentNamespace: currentNamespace,
50-
currentNamespaceCient: currentNamespaceClient,
50+
serviceName: ctx.Config.WorkloadService,
51+
currentNamespace: ctx.Config.WorkloadNamespace,
52+
currentNamespaceCient: ctx.WorkloadNamespaceClient,
5153
}, nil
5254
}
5355

5456
type syncer struct {
5557
clusterDomain string
5658

59+
ingressHost string
60+
5761
serverCaCert string
5862
serverCaKey string
5963

@@ -187,6 +191,11 @@ func (s *syncer) getSANs(ctx context.Context) ([]string, error) {
187191
}
188192
}
189193

194+
// ingress host
195+
if s.ingressHost != "" {
196+
retSANs = append(retSANs, s.ingressHost)
197+
}
198+
190199
// make sure other sans are there as well
191200
retSANs = append(retSANs, s.addSANs...)
192201
sort.Strings(retSANs)

pkg/server/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func NewServer(ctx *synccontext.ControllerContext, requestHeaderCaFile, clientCa
9090
uncachedVirtualClient = pluginhookclient.WrapVirtualClient(uncachedVirtualClient)
9191
uncachedLocalClient = pluginhookclient.WrapPhysicalClient(uncachedLocalClient)
9292

93-
certSyncer, err := cert.NewSyncer(ctx, ctx.Config.WorkloadNamespace, ctx.WorkloadNamespaceClient, ctx.Config)
93+
certSyncer, err := cert.NewSyncer(ctx)
9494
if err != nil {
9595
return nil, errors.Wrap(err, "create cert syncer")
9696
}

0 commit comments

Comments
 (0)