Skip to content

Commit

Permalink
Have nodeup assign an ipv6 prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
Ole Markus With committed Aug 6, 2021
1 parent 70a6064 commit a684180
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 4 deletions.
1 change: 1 addition & 0 deletions nodeup/pkg/model/BUILD.bazel

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions nodeup/pkg/model/prefix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
Copyright 2021 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 model

import (
"k8s.io/kops/upup/pkg/fi"
"k8s.io/kops/upup/pkg/fi/nodeup/nodetasks"
)

type PrefixBuilder struct {
*NodeupModelContext
}

var _ fi.ModelBuilder = &PrefixBuilder{}

func (b *PrefixBuilder) Build(c *fi.ModelBuilderContext) error {
c.AddTask(&nodetasks.Prefix{
Name: "prefix",
})
return nil
}
7 changes: 7 additions & 0 deletions pkg/model/iam/iam_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,13 @@ func addNodeupPermissions(p *Policy, enableHookSupport bool) {
addASLifecyclePolicies(p, enableHookSupport)
p.unconditionalAction.Insert(
"ec2:DescribeInstances", // aws.go
"ec2:CreateNetworkInterface",
"ec2:AttachNetworkInterface",
"ec2:DescribeNetworkInterfaces",
"ec2:DescribeSecurityGroups",
"ec2:ModifyNetworkInterfaceAttribute",
"ec2:AssignIpv6Addresses",
"ec2:CreateTags",
)
}

Expand Down
6 changes: 5 additions & 1 deletion upup/pkg/fi/nodeup/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ func (c *NodeUpCommand) Run(out io.Writer) error {
loader.Builders = append(loader.Builders, &model.KubeProxyBuilder{NodeupModelContext: modelContext})
loader.Builders = append(loader.Builders, &model.KopsControllerBuilder{NodeupModelContext: modelContext})
loader.Builders = append(loader.Builders, &model.WarmPoolBuilder{NodeupModelContext: modelContext})
loader.Builders = append(loader.Builders, &model.PrefixBuilder{NodeupModelContext: modelContext})

loader.Builders = append(loader.Builders, &networking.CommonBuilder{NodeupModelContext: modelContext})
loader.Builders = append(loader.Builders, &networking.CalicoBuilder{NodeupModelContext: modelContext})
Expand Down Expand Up @@ -331,7 +332,10 @@ func (c *NodeUpCommand) Run(out io.Writer) error {
switch c.Target {
case "direct":
target = &local.LocalTarget{
CacheDir: c.CacheDir,
CacheDir: c.CacheDir,
Cloud: cloud,
InstanceID: modelContext.InstanceID,
Cluster: c.cluster,
}
case "dryrun":
assetBuilder := assets.NewAssetBuilder(c.cluster, false)
Expand Down
5 changes: 4 additions & 1 deletion upup/pkg/fi/nodeup/local/BUILD.bazel

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion upup/pkg/fi/nodeup/local/local_target.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ package local
import (
"os/exec"

"k8s.io/kops/pkg/apis/kops"
"k8s.io/kops/upup/pkg/fi"
)

type LocalTarget struct {
CacheDir string
CacheDir string
Cloud fi.Cloud
InstanceID string
Cluster *kops.Cluster
}

var _ fi.Target = &LocalTarget{}
Expand Down
3 changes: 3 additions & 0 deletions upup/pkg/fi/nodeup/nodetasks/BUILD.bazel

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

83 changes: 83 additions & 0 deletions upup/pkg/fi/nodeup/nodetasks/prefix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
Copyright 2021 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 nodetasks

import (
"fmt"

"github.com/aws/aws-sdk-go/service/ec2"
"k8s.io/kops/upup/pkg/fi"
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
"k8s.io/kops/upup/pkg/fi/nodeup/local"
)

type Prefix struct {
Name string
}

var _ fi.HasName = &Prefix{}

func (f *Prefix) GetName() *string {
return &f.Name
}

// String returns a string representation, implementing the Stringer interface
func (p *Prefix) String() string {
return fmt.Sprintf("Prefix: %s", p.Name)
}

func (e *Prefix) Find(c *fi.Context) (*Prefix, error) {
return nil, nil
}
func (e *Prefix) Run(c *fi.Context) error {
return fi.DefaultDeltaRunMethod(e, c)
}

func (_ *Prefix) CheckChanges(a, e, changes *Prefix) error {
return nil
}

func (_ *Prefix) RenderLocal(t *local.LocalTarget, a, e, changes *Prefix) error {

awsCloud := t.Cloud.(awsup.AWSCloud)

netifs, err := awsCloud.EC2().DescribeNetworkInterfaces(&ec2.DescribeNetworkInterfacesInput{
Filters: []*ec2.Filter{
{
Name: fi.String("attachment.instance-id"),
Values: []*string{
&t.InstanceID,
},
},
},
})
if err != nil {
return fmt.Errorf("failed to get interface: %w", err)
}

netif := netifs.NetworkInterfaces[0]

_, err = awsCloud.EC2().AssignIpv6Addresses(&ec2.AssignIpv6AddressesInput{
Ipv6PrefixCount: fi.Int64(1),
NetworkInterfaceId: netif.NetworkInterfaceId,
})
if err != nil {
return fmt.Errorf("failed to assign ip address: %w", err)
}

return nil
}
2 changes: 1 addition & 1 deletion upup/pkg/fi/nodeup/nodetasks/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (p *Service) GetDependencies(tasks map[string]fi.Task) []fi.Task {
// launching a custom Kubernetes build), they all depend on
// the "docker.service" Service task.
switch v := v.(type) {
case *Package, *UpdatePackages, *UserTask, *GroupTask, *Chattr, *BindMount, *Archive:
case *Package, *UpdatePackages, *UserTask, *GroupTask, *Chattr, *BindMount, *Archive, *Prefix:
deps = append(deps, v)
case *Service, *LoadImageTask, *PullImageTask, *IssueCert, *BootstrapClientTask, *KubeConfig:
// ignore
Expand Down

0 comments on commit a684180

Please sign in to comment.