forked from kubernetes-sigs/kind
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d123d39
commit 47043cc
Showing
10 changed files
with
300 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
Copyright 2019 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 actions | ||
|
||
import ( | ||
"sync" | ||
|
||
"sigs.k8s.io/kind/pkg/cluster/nodes" | ||
"sigs.k8s.io/kind/pkg/cluster/nodeutils" | ||
"sigs.k8s.io/kind/pkg/internal/apis/config" | ||
"sigs.k8s.io/kind/pkg/internal/cli" | ||
"sigs.k8s.io/kind/pkg/log" | ||
|
||
"sigs.k8s.io/kind/pkg/cluster/internal/providers" | ||
) | ||
|
||
// Action defines a step of bringing up a kind cluster after initial node | ||
// container creation | ||
type Action interface { | ||
Execute(ctx *ActionContext) error | ||
} | ||
|
||
// ActionContext is data supplied to all actions | ||
type ActionContext struct { | ||
Logger log.Logger | ||
Status *cli.Status | ||
Config *config.Cluster | ||
Provider providers.Provider | ||
cache *cachedData | ||
} | ||
|
||
// NewActionContext returns a new ActionContext | ||
func NewActionContext( | ||
logger log.Logger, | ||
status *cli.Status, | ||
provider providers.Provider, | ||
cfg *config.Cluster, | ||
) *ActionContext { | ||
return &ActionContext{ | ||
Logger: logger, | ||
Status: status, | ||
Provider: provider, | ||
Config: cfg, | ||
cache: &cachedData{}, | ||
} | ||
} | ||
|
||
type cachedData struct { | ||
mu sync.RWMutex | ||
nodes []nodes.Node | ||
} | ||
|
||
func (cd *cachedData) getNodes() []nodes.Node { | ||
cd.mu.RLock() | ||
defer cd.mu.RUnlock() | ||
return cd.nodes | ||
} | ||
|
||
func (cd *cachedData) setNodes(n []nodes.Node) { | ||
cd.mu.Lock() | ||
defer cd.mu.Unlock() | ||
cd.nodes = n | ||
} | ||
|
||
// Nodes returns the list of cluster nodes, this is a cached call | ||
func (ac *ActionContext) Nodes() ([]nodes.Node, error) { | ||
cachedNodes := ac.cache.getNodes() | ||
if cachedNodes != nil { | ||
return cachedNodes, nil | ||
} | ||
n, err := ac.Provider.ListNodes(ac.Config.Name) | ||
if err != nil { | ||
return nil, err | ||
} | ||
ac.cache.setNodes(n) | ||
return n, nil | ||
} | ||
|
||
func (ac *ActionContext) GetNode() (nodes.Node, error) { | ||
allNodes, err := ac.Nodes() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
controlPlanes, err := nodeutils.ControlPlaneNodes(allNodes) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return controlPlanes[0], nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
17 changes: 17 additions & 0 deletions
17
pkg/cluster/internal/create/actions/createworker/files/azure/allow-egress-imds_gnetpol.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
apiVersion: crd.projectcalico.org/v1 | ||
kind: GlobalNetworkPolicy | ||
metadata: | ||
name: allow-traffic-to-azure-imds-capz | ||
spec: | ||
egress: | ||
- action: Allow | ||
destination: | ||
nets: | ||
- 169.254.169.254/32 | ||
protocol: TCP | ||
order: 0 | ||
namespaceSelector: kubernetes.io/metadata.name in { 'kube-system', 'capz-system' } | ||
selector: app.kubernetes.io/name == 'azuredisk-csi-driver' || cluster.x-k8s.io/provider == 'infrastructure-azure' | ||
types: | ||
- Egress |
20 changes: 20 additions & 0 deletions
20
...luster/internal/create/actions/createworker/files/azure/deny-all-egress-imds_gnetpol.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
apiVersion: crd.projectcalico.org/v1 | ||
kind: GlobalNetworkPolicy | ||
metadata: | ||
name: deny-all-traffic-to-azure-imds | ||
spec: | ||
egress: | ||
- action: Deny | ||
destination: | ||
nets: | ||
- 169.254.169.254/32 | ||
protocol: TCP | ||
order: 10 | ||
selector: all() | ||
types: | ||
- Egress | ||
|
||
|
||
|
||
|
Oops, something went wrong.