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

scaleway: private network implementation #16490

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions cmd/kops/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,11 +453,10 @@ func TestMinimalGCEDNSNone(t *testing.T) {
// TestMinimalScaleway runs tests on a minimal Scaleway cluster with gossip DNS
func TestMinimalScaleway(t *testing.T) {
t.Setenv("SCW_PROFILE", "REDACTED")
newIntegrationTest("scw-minimal.k8s.local", "minimal_scaleway").
newIntegrationTest("scw-minimal.example.com", "minimal_scaleway").
withAddons(
scwCCMAddon,
scwCSIAddon,
dnsControllerAddon,
).
runTestTerraformScaleway(t)
}
Expand Down
3 changes: 3 additions & 0 deletions dnsprovider/pkg/dnsprovider/providers/scaleway/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ func (z *zones) List() ([]dnsprovider.Zone, error) {

zonesList := []dnsprovider.Zone(nil)
for _, dnsZone := range dnsZones.DNSZones {
if dnsZone.Domain == "privatedns" {
continue
}
newZone := &zone{
name: dnsZone.Domain,
domainAPI: z.domainAPI,
Expand Down
1 change: 1 addition & 0 deletions pkg/model/scalewaymodel/api_loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func (b *APILoadBalancerModelBuilder) Build(c *fi.CloudupModelBuilderContext) er
Tags: lbTags,
Description: "Load-balancer for kops cluster " + b.ClusterName(),
SslCompatibilityLevel: string(lb.SSLCompatibilityLevelSslCompatibilityLevelUnknown),
PrivateNetwork: b.LinkToNetwork(),
}

c.AddTask(loadBalancer)
Expand Down
6 changes: 6 additions & 0 deletions pkg/model/scalewaymodel/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@ package scalewaymodel

import (
"k8s.io/kops/pkg/model"
"k8s.io/kops/upup/pkg/fi/cloudup/scalewaytasks"
)

type ScwModelContext struct {
*model.KopsModelContext
}

func (b *ScwModelContext) LinkToNetwork() *scalewaytasks.PrivateNetwork {
name := b.ClusterName()
return &scalewaytasks.PrivateNetwork{Name: &name}
}
43 changes: 24 additions & 19 deletions pkg/model/scalewaymodel/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
)

const (
placeholderIP = "203.0.113.123"
kopsControllerInternalRecordPrefix = "kops-controller.internal."
defaultTTL = uint32(60)
)
Expand All @@ -45,38 +44,44 @@ func (b *DNSModelBuilder) Build(c *fi.CloudupModelBuilderContext) error {
if !b.UseLoadBalancerForAPI() {
recordShortName := strings.TrimSuffix(b.Cluster.Spec.API.PublicName, "."+b.Cluster.Spec.DNSZone)
dnsAPIExternal := &scalewaytasks.DNSRecord{
Name: fi.PtrTo(recordShortName),
Data: fi.PtrTo(placeholderIP),
DNSZone: fi.PtrTo(b.Cluster.Spec.DNSZone),
Type: fi.PtrTo(domain.RecordTypeA.String()),
TTL: fi.PtrTo(defaultTTL),
Lifecycle: b.Lifecycle,
Name: fi.PtrTo(recordShortName),
Data: fi.PtrTo(scalewaytasks.PlaceholderIP),
DNSZone: fi.PtrTo(b.Cluster.Spec.DNSZone),
Type: fi.PtrTo(domain.RecordTypeA.String()),
TTL: fi.PtrTo(defaultTTL),
Lifecycle: b.Lifecycle,
IsInternal: fi.PtrTo(false),
ClusterName: fi.PtrTo(b.Cluster.Name),
}
c.AddTask(dnsAPIExternal)
}

if !b.UseLoadBalancerForInternalAPI() {
recordShortName := strings.TrimSuffix(b.Cluster.APIInternalName(), "."+b.Cluster.Spec.DNSZone)
dnsAPIInternal := &scalewaytasks.DNSRecord{
Name: fi.PtrTo(recordShortName),
Data: fi.PtrTo(placeholderIP),
DNSZone: fi.PtrTo(b.Cluster.Spec.DNSZone),
Type: fi.PtrTo(domain.RecordTypeA.String()),
TTL: fi.PtrTo(defaultTTL),
Lifecycle: b.Lifecycle,
Name: fi.PtrTo(recordShortName),
Data: fi.PtrTo(scalewaytasks.PlaceholderIP),
DNSZone: fi.PtrTo(b.Cluster.Spec.DNSZone),
Type: fi.PtrTo(domain.RecordTypeA.String()),
TTL: fi.PtrTo(defaultTTL),
IsInternal: fi.PtrTo(true),
ClusterName: fi.PtrTo(b.Cluster.Name),
Lifecycle: b.Lifecycle,
}
c.AddTask(dnsAPIInternal)
}

recordSuffix := strings.TrimSuffix(b.Cluster.ObjectMeta.Name, "."+b.Cluster.Spec.DNSZone)
recordShortName := kopsControllerInternalRecordPrefix + recordSuffix
kopsControllerInternal := &scalewaytasks.DNSRecord{
Name: fi.PtrTo(recordShortName),
Data: fi.PtrTo(placeholderIP),
DNSZone: fi.PtrTo(b.Cluster.Spec.DNSZone),
Type: fi.PtrTo(domain.RecordTypeA.String()),
TTL: fi.PtrTo(defaultTTL),
Lifecycle: b.Lifecycle,
Name: fi.PtrTo(recordShortName),
Data: fi.PtrTo(scalewaytasks.PlaceholderIP),
DNSZone: fi.PtrTo(b.Cluster.Spec.DNSZone),
Type: fi.PtrTo(domain.RecordTypeA.String()),
TTL: fi.PtrTo(defaultTTL),
IsInternal: fi.PtrTo(true),
ClusterName: fi.PtrTo(b.Cluster.Name),
Lifecycle: b.Lifecycle,
}
c.AddTask(kopsControllerInternal)

Expand Down
21 changes: 18 additions & 3 deletions pkg/model/scalewaymodel/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ var _ fi.CloudupModelBuilder = &InstanceModelBuilder{}
func (b *InstanceModelBuilder) Build(c *fi.CloudupModelBuilderContext) error {
for _, ig := range b.InstanceGroups {
name := ig.Name
count := int(fi.ValueOf(ig.Spec.MinSize))
zone, err := scw.ParseZone(ig.Spec.Subnets[0])
if err != nil {
return fmt.Errorf("error building instance task for %q: %w", name, err)
Expand All @@ -63,21 +64,23 @@ func (b *InstanceModelBuilder) Build(c *fi.CloudupModelBuilderContext) error {
instanceTags = append(instanceTags, fmt.Sprintf("%s=%s", k, v))
}

instance := scalewaytasks.Instance{
Count: int(fi.ValueOf(ig.Spec.MinSize)),
instance := &scalewaytasks.Instance{
Count: count,
Name: fi.PtrTo(name),
Lifecycle: b.Lifecycle,
Zone: fi.PtrTo(string(zone)),
CommercialType: fi.PtrTo(ig.Spec.MachineType),
Image: fi.PtrTo(ig.Spec.Image),
UserData: &userData,
Tags: instanceTags,
PrivateNetwork: b.LinkToNetwork(),
}

if ig.IsControlPlane() {
instance.Tags = append(instance.Tags, scaleway.TagNameRolePrefix+"="+scaleway.TagRoleControlPlane)
instance.Role = fi.PtrTo(scaleway.TagRoleControlPlane)
} else {
instance.Tags = append(instance.Tags, scaleway.TagNameRolePrefix+"="+scaleway.TagRoleWorker)
instance.Role = fi.PtrTo(scaleway.TagRoleWorker)
}

Expand All @@ -94,7 +97,19 @@ func (b *InstanceModelBuilder) Build(c *fi.CloudupModelBuilderContext) error {
}
}

c.AddTask(&instance)
c.AddTask(instance)

// For each individual server of the instance group, we add a PrivateNIC task to link the server to the private network.
privateNIC := &scalewaytasks.PrivateNIC{
Name: &name,
Zone: fi.PtrTo(string(zone)),
Tags: instanceTags,
Count: count,
Lifecycle: b.Lifecycle,
Instance: instance,
PrivateNetwork: b.LinkToNetwork(),
}
c.AddTask(privateNIC)
}
return nil
}
85 changes: 85 additions & 0 deletions pkg/model/scalewaymodel/network.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
Copyright 2024 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package scalewaymodel

import (
"fmt"

"github.com/scaleway/scaleway-sdk-go/scw"
"k8s.io/kops/upup/pkg/fi"
"k8s.io/kops/upup/pkg/fi/cloudup/scaleway"
"k8s.io/kops/upup/pkg/fi/cloudup/scalewaytasks"
)

// NetworkModelBuilder configures network objects
type NetworkModelBuilder struct {
*ScwModelContext
Lifecycle fi.Lifecycle
}

func (b *NetworkModelBuilder) Build(c *fi.CloudupModelBuilderContext) error {
clusterNameTag := scaleway.TagClusterName + "=" + b.ClusterName()
resourceName := b.ClusterName()
zone := scw.Zone(b.Cluster.Spec.Networking.Subnets[0].Zone)
region, err := zone.Region()
if err != nil {
return fmt.Errorf("building network task: %w", err)
}

vpc := &scalewaytasks.VPC{
Name: fi.PtrTo(resourceName),
Region: fi.PtrTo(region.String()),
Tags: []string{clusterNameTag},
Lifecycle: b.Lifecycle,
}
c.AddTask(vpc)

ipRange := b.Cluster.Spec.Networking.NetworkCIDR
if ipRange == "" {
ipRange = "192.168.1.0/24"
}

privateNetwork := &scalewaytasks.PrivateNetwork{
Name: fi.PtrTo(resourceName),
Region: fi.PtrTo(region.String()),
Tags: []string{clusterNameTag},
Lifecycle: b.Lifecycle,
IPRange: fi.PtrTo(ipRange),
VPC: vpc,
}
c.AddTask(privateNetwork)

gateway := &scalewaytasks.Gateway{
Name: fi.PtrTo(resourceName),
Zone: fi.PtrTo(zone.String()),
Tags: []string{clusterNameTag},
Lifecycle: b.Lifecycle,
//PrivateNetwork: privateNetwork,
}
c.AddTask(gateway)

gatewayNetwork := &scalewaytasks.GatewayNetwork{
Name: fi.PtrTo(resourceName),
Zone: fi.PtrTo(zone.String()),
Lifecycle: b.Lifecycle,
Gateway: gateway,
PrivateNetwork: privateNetwork,
}
c.AddTask(gatewayNetwork)

return nil
}