Skip to content

Commit

Permalink
refactor: pull new version of os-runtime, update code
Browse files Browse the repository at this point in the history
This is mostly refactoring to adapt to the new APIs.

There are some small changes which are not user-visible immediately (but
visible when using `talosctl get` to inspect low-level details):

* `extras` namespace is removed, it was a hack to distinguish extra and
system manifests
* `Manifests` are managed by two controllers as shared outputs, stored
in the `controlplane` namespace now
* `talosctl inspect dependencies` output got slightly changed
* resources now have `md.owner` set to the controller name which manages
the resource

Signed-off-by: Andrey Smirnov <[email protected]>
  • Loading branch information
smira authored and talos-bot committed Apr 7, 2021
1 parent 8737ea7 commit fbfd1eb
Show file tree
Hide file tree
Showing 34 changed files with 487 additions and 380 deletions.
7 changes: 4 additions & 3 deletions api/inspect/inspect.proto
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ message ControllerRuntimeDependency {
message ControllerRuntimeDependenciesResponse { repeated ControllerRuntimeDependency messages = 1; }

enum DependencyEdgeType {
MANAGES = 0;
STRONG = 1;
WEAK = 2;
OUTPUT_EXCLUSIVE = 0;
OUTPUT_SHARED = 3;
INPUT_STRONG = 1;
INPUT_WEAK = 2;
}

message ControllerDependencyEdge {
Expand Down
1 change: 1 addition & 0 deletions api/resource/resource.proto
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ message Metadata {
string type = 2;
string id = 3;
string version = 4;
string owner = 7;
string phase = 5;
repeated string finalizers = 6;
}
Expand Down
26 changes: 18 additions & 8 deletions cmd/talosctl/cmd/talos/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ to render the graph:
graph := dot.NewGraph(dot.Directed)

resourceTypeID := func(edge *inspect.ControllerDependencyEdge) string {
return fmt.Sprintf("%s:%s", edge.GetResourceNamespace(), edge.GetResourceType())
return edge.GetResourceType()
}

resourceID := func(r resource.Resource) string {
return r.Metadata().ID()
return fmt.Sprintf("%s/%s/%s", r.Metadata().Namespace(), r.Metadata().Type(), r.Metadata().ID())
}

if inspectDependenciesCmdFlags.withResources {
Expand Down Expand Up @@ -127,12 +127,20 @@ to render the graph:
continue
}

if (edge.GetEdgeType() == inspect.DependencyEdgeType_OUTPUT_EXCLUSIVE ||
edge.GetEdgeType() == inspect.DependencyEdgeType_OUTPUT_SHARED) &&
edge.GetControllerName() != resource.Metadata().Owner() {
continue
}

switch edge.GetEdgeType() {
case inspect.DependencyEdgeType_MANAGES:
case inspect.DependencyEdgeType_OUTPUT_EXCLUSIVE:
graph.Edge(graph.Node(edge.ControllerName), graph.Subgraph(resourceTypeID(edge)).Node(resourceID(resource))).Solid()
case inspect.DependencyEdgeType_OUTPUT_SHARED:
graph.Edge(graph.Node(edge.ControllerName), graph.Subgraph(resourceTypeID(edge)).Node(resourceID(resource))).Solid()
case inspect.DependencyEdgeType_STRONG:
case inspect.DependencyEdgeType_INPUT_STRONG:
graph.Edge(graph.Subgraph(resourceTypeID(edge)).Node(resourceID(resource)), graph.Node(edge.ControllerName)).Solid()
case inspect.DependencyEdgeType_WEAK:
case inspect.DependencyEdgeType_INPUT_WEAK:
graph.Edge(graph.Subgraph(resourceTypeID(edge)).Node(resourceID(resource)), graph.Node(edge.ControllerName)).Dotted()
}
}
Expand All @@ -159,11 +167,13 @@ to render the graph:
}

switch edge.GetEdgeType() {
case inspect.DependencyEdgeType_MANAGES:
case inspect.DependencyEdgeType_OUTPUT_EXCLUSIVE:
graph.Edge(graph.Node(edge.ControllerName), graph.Node(resourceTypeID(edge))).Bold()
case inspect.DependencyEdgeType_STRONG:
case inspect.DependencyEdgeType_OUTPUT_SHARED:
graph.Edge(graph.Node(edge.ControllerName), graph.Node(resourceTypeID(edge))).Solid()
case inspect.DependencyEdgeType_INPUT_STRONG:
graph.Edge(graph.Node(resourceTypeID(edge)), graph.Node(edge.ControllerName), idLabels...).Solid()
case inspect.DependencyEdgeType_WEAK:
case inspect.DependencyEdgeType_INPUT_WEAK:
graph.Edge(graph.Node(resourceTypeID(edge)), graph.Node(edge.ControllerName), idLabels...).Dotted()
}
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ require (
github.com/talos-systems/go-smbios v0.0.0-20201228201610-fb425d4727e6
github.com/talos-systems/grpc-proxy v0.2.0
github.com/talos-systems/net v0.2.1-0.20210212213224-05190541b0fa
github.com/talos-systems/os-runtime v0.0.0-20210315190223-7b3d14457439
github.com/talos-systems/os-runtime v0.0.0-20210401122348-86d9e090bdc4
github.com/talos-systems/talos/pkg/machinery v0.0.0-20210302191918-8ffb55943c71
github.com/u-root/u-root v7.0.0+incompatible
github.com/vmware-tanzu/sonobuoy v0.20.0
Expand Down
10 changes: 4 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -577,8 +577,8 @@ github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjh
github.com/hashicorp/go-immutable-radix v1.2.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
github.com/hashicorp/go-immutable-radix v1.3.0 h1:8exGP7ego3OmkfksihtSouGMZ+hQrhxx+FVELeXpVPE=
github.com/hashicorp/go-immutable-radix v1.3.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
github.com/hashicorp/go-memdb v1.3.0 h1:xdXq34gBOMEloa9rlGStLxmfX/dyIK8htOv36dQUwHU=
github.com/hashicorp/go-memdb v1.3.0/go.mod h1:Mluclgwib3R93Hk5fxEfiRhB+6Dar64wWh71LpNSe3g=
github.com/hashicorp/go-memdb v1.3.2 h1:RBKHOsnSszpU6vxq80LzC2BaQjuuvoyaQbkLTf7V7g8=
github.com/hashicorp/go-memdb v1.3.2/go.mod h1:Mluclgwib3R93Hk5fxEfiRhB+6Dar64wWh71LpNSe3g=
github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM=
github.com/hashicorp/go-msgpack v0.5.5/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM=
github.com/hashicorp/go-msgpack v1.1.5/go.mod h1:gWVc3sv/wbDmR3rQsj1CAktEZzoz1YNK9NfGLXJ69/4=
Expand Down Expand Up @@ -1003,7 +1003,6 @@ github.com/talos-systems/go-procfs v0.0.0-20210108152626-8cbc42d3dc24 h1:fN8vYvl
github.com/talos-systems/go-procfs v0.0.0-20210108152626-8cbc42d3dc24/go.mod h1:ATyUGFQIW8OnbnmvqefZWVPgL9g+CAmXHfkgny21xX8=
github.com/talos-systems/go-retry v0.1.0/go.mod h1:HiXQqyVStZ35uSY/MTLWVvQVmC3lIW2MS5VdDaMtoKM=
github.com/talos-systems/go-retry v0.1.1-0.20201113203059-8c63d290a688/go.mod h1:HiXQqyVStZ35uSY/MTLWVvQVmC3lIW2MS5VdDaMtoKM=
github.com/talos-systems/go-retry v0.2.0/go.mod h1:HiXQqyVStZ35uSY/MTLWVvQVmC3lIW2MS5VdDaMtoKM=
github.com/talos-systems/go-retry v0.2.1-0.20210119124456-b9dc1a990133 h1:mHnKEViee9x2A6YbsUykwqh7L+tLpm5HTlos2QDlqts=
github.com/talos-systems/go-retry v0.2.1-0.20210119124456-b9dc1a990133/go.mod h1:HiXQqyVStZ35uSY/MTLWVvQVmC3lIW2MS5VdDaMtoKM=
github.com/talos-systems/go-smbios v0.0.0-20201228201610-fb425d4727e6 h1:xyE29iB9cVeFZs7WS2RG57MikJt8q6hIQvQajMWiloM=
Expand All @@ -1012,9 +1011,8 @@ github.com/talos-systems/grpc-proxy v0.2.0 h1:DN75bLfaW4xfhq0r0mwFRnfGhSB+HPhK1L
github.com/talos-systems/grpc-proxy v0.2.0/go.mod h1:sm97Vc/z2cok3pu6ruNeszQej4KDxFrDgfWs4C1mtC4=
github.com/talos-systems/net v0.2.1-0.20210212213224-05190541b0fa h1:XqOMTt0Q6mjsk8Dea5wUpgcdtf+AzesH11m4AozWSxw=
github.com/talos-systems/net v0.2.1-0.20210212213224-05190541b0fa/go.mod h1:VreSAyRmxMtqussAHSKMKkJQa1YwBTSVfkmE4Jydam4=
github.com/talos-systems/os-runtime v0.0.0-20210303124137-84c3c875eb2b/go.mod h1:Z+1phKVJ0IWH+Jd2DGufL8WKqxd3xt1xlcsxcU18ZL0=
github.com/talos-systems/os-runtime v0.0.0-20210315190223-7b3d14457439 h1:3Q7eMWbwg1pndsvOo/VV8mgQKweDDvPczLZu7LAS9+o=
github.com/talos-systems/os-runtime v0.0.0-20210315190223-7b3d14457439/go.mod h1:B2hrj55wAJ3RJxConurFKlFGhm7mkF3zWw5DBQw8LvA=
github.com/talos-systems/os-runtime v0.0.0-20210401122348-86d9e090bdc4 h1:mVlqonAE7QgFWn1g9p2b+EBC4Lk57TexASvp7tHglRc=
github.com/talos-systems/os-runtime v0.0.0-20210401122348-86d9e090bdc4/go.mod h1:358qvRxAR16NdF8fiitixPgECx4Pj32yXLHAWYWZc/g=
github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ func (s *InspectServer) ControllerRuntimeDependencies(ctx context.Context, in *e
var edgeType inspectapi.DependencyEdgeType

switch graph.Edges[i].EdgeType {
case controller.EdgeManages:
edgeType = inspectapi.DependencyEdgeType_MANAGES
case controller.EdgeDependsStrong:
edgeType = inspectapi.DependencyEdgeType_STRONG
case controller.EdgeDependsWeak:
edgeType = inspectapi.DependencyEdgeType_WEAK
case controller.EdgeOutputExclusive:
edgeType = inspectapi.DependencyEdgeType_OUTPUT_EXCLUSIVE
case controller.EdgeOutputShared:
edgeType = inspectapi.DependencyEdgeType_OUTPUT_SHARED
case controller.EdgeInputStrong:
edgeType = inspectapi.DependencyEdgeType_INPUT_STRONG
case controller.EdgeInputWeak:
edgeType = inspectapi.DependencyEdgeType_INPUT_WEAK
}

edges = append(edges, &inspectapi.ControllerDependencyEdge{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func marshalResource(r resource.Resource) (*resourceapi.Resource, error) {
Id: r.Metadata().ID(),
Version: r.Metadata().Version().String(),
Phase: r.Metadata().Phase().String(),
Owner: r.Metadata().Owner(),
}

for _, fin := range *r.Metadata().Finalizers() {
Expand Down
44 changes: 25 additions & 19 deletions internal/app/machined/pkg/controllers/config/k8s_control_plane.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,38 @@ func (ctrl *K8sControlPlaneController) Name() string {
return "config.K8sControlPlaneController"
}

// ManagedResources implements controller.Controller interface.
func (ctrl *K8sControlPlaneController) ManagedResources() (resource.Namespace, resource.Type) {
return config.NamespaceName, config.K8sControlPlaneType
}

// Run implements controller.Controller interface.
//
//nolint:gocyclo
func (ctrl *K8sControlPlaneController) Run(ctx context.Context, r controller.Runtime, logger *log.Logger) error {
if err := r.UpdateDependencies([]controller.Dependency{
// Inputs implements controller.Controller interface.
func (ctrl *K8sControlPlaneController) Inputs() []controller.Input {
return []controller.Input{
{
Namespace: config.NamespaceName,
Type: config.MachineConfigType,
ID: pointer.ToString(config.V1Alpha1ID),
Kind: controller.DependencyWeak,
Kind: controller.InputWeak,
},
{
Namespace: config.NamespaceName,
Type: config.MachineTypeType,
ID: pointer.ToString(config.MachineTypeID),
Kind: controller.DependencyWeak,
Kind: controller.InputWeak,
},
}
}

// Outputs implements controller.Controller interface.
func (ctrl *K8sControlPlaneController) Outputs() []controller.Output {
return []controller.Output{
{
Type: config.K8sControlPlaneType,
Kind: controller.OutputExclusive,
},
}); err != nil {
return fmt.Errorf("error setting up dependencies: %w", err)
}
}

// Run implements controller.Controller interface.
//
//nolint:gocyclo
func (ctrl *K8sControlPlaneController) Run(ctx context.Context, r controller.Runtime, logger *log.Logger) error {
for {
select {
case <-ctx.Done():
Expand Down Expand Up @@ -133,7 +139,7 @@ func (ctrl *K8sControlPlaneController) manageAPIServerConfig(ctx context.Context
cloudProvider = "external"
}

return r.Update(ctx, config.NewK8sControlPlaneAPIServer(), func(r resource.Resource) error {
return r.Modify(ctx, config.NewK8sControlPlaneAPIServer(), func(r resource.Resource) error {
r.(*config.K8sControlPlane).SetAPIServer(config.K8sControlPlaneAPIServerSpec{
Image: cfgProvider.Cluster().APIServer().Image(),
CloudProvider: cloudProvider,
Expand All @@ -155,7 +161,7 @@ func (ctrl *K8sControlPlaneController) manageControllerManagerConfig(ctx context
cloudProvider = "external"
}

return r.Update(ctx, config.NewK8sControlPlaneControllerManager(), func(r resource.Resource) error {
return r.Modify(ctx, config.NewK8sControlPlaneControllerManager(), func(r resource.Resource) error {
r.(*config.K8sControlPlane).SetControllerManager(config.K8sControlPlaneControllerManagerSpec{
Image: cfgProvider.Cluster().ControllerManager().Image(),
CloudProvider: cloudProvider,
Expand All @@ -170,7 +176,7 @@ func (ctrl *K8sControlPlaneController) manageControllerManagerConfig(ctx context
}

func (ctrl *K8sControlPlaneController) manageSchedulerConfig(ctx context.Context, r controller.Runtime, logger *log.Logger, cfgProvider talosconfig.Provider) error {
return r.Update(ctx, config.NewK8sControlPlaneScheduler(), func(r resource.Resource) error {
return r.Modify(ctx, config.NewK8sControlPlaneScheduler(), func(r resource.Resource) error {
r.(*config.K8sControlPlane).SetScheduler(config.K8sControlPlaneSchedulerSpec{
Image: cfgProvider.Cluster().Scheduler().Image(),
ExtraArgs: cfgProvider.Cluster().Scheduler().ExtraArgs(),
Expand Down Expand Up @@ -204,7 +210,7 @@ func (ctrl *K8sControlPlaneController) manageManifestsConfig(ctx context.Context
}
}

return r.Update(ctx, config.NewK8sManifests(), func(r resource.Resource) error {
return r.Modify(ctx, config.NewK8sManifests(), func(r resource.Resource) error {
images := images.List(cfgProvider)

r.(*config.K8sControlPlane).SetManifests(config.K8sManifestsSpec{
Expand Down Expand Up @@ -234,7 +240,7 @@ func (ctrl *K8sControlPlaneController) manageManifestsConfig(ctx context.Context
}

func (ctrl *K8sControlPlaneController) manageExtraManifestsConfig(ctx context.Context, r controller.Runtime, logger *log.Logger, cfgProvider talosconfig.Provider) error {
return r.Update(ctx, config.NewK8sExtraManifests(), func(r resource.Resource) error {
return r.Modify(ctx, config.NewK8sExtraManifests(), func(r resource.Resource) error {
spec := config.K8sExtraManifestsSpec{}

if cfgProvider.Cluster().Network().CNI().Name() == constants.CustomCNI {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func (suite *K8sControlPlaneSuite) TearDownTest() {

// trigger updates in resources to stop watch loops
suite.Assert().NoError(suite.state.Create(context.Background(), k8s.NewSecretsStatus(k8s.ControlPlaneNamespaceName, "-")))
suite.Assert().NoError(suite.state.Destroy(context.Background(), config.NewK8sControlPlaneAPIServer().Metadata()))
suite.Assert().NoError(suite.state.Destroy(context.Background(), config.NewK8sControlPlaneAPIServer().Metadata(), state.WithDestroyOwner("config.K8sControlPlaneController")))
}

func TestK8sControlPlaneSuite(t *testing.T) {
Expand Down
30 changes: 18 additions & 12 deletions internal/app/machined/pkg/controllers/config/machine_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,30 @@ func (ctrl *MachineTypeController) Name() string {
return "config.MachineTypeController"
}

// ManagedResources implements controller.Controller interface.
func (ctrl *MachineTypeController) ManagedResources() (resource.Namespace, resource.Type) {
return config.NamespaceName, config.MachineTypeType
}

// Run implements controller.Controller interface.
func (ctrl *MachineTypeController) Run(ctx context.Context, r controller.Runtime, logger *log.Logger) error {
if err := r.UpdateDependencies([]controller.Dependency{
// Inputs implements controller.Controller interface.
func (ctrl *MachineTypeController) Inputs() []controller.Input {
return []controller.Input{
{
Namespace: config.NamespaceName,
Type: config.MachineConfigType,
ID: pointer.ToString(config.V1Alpha1ID),
Kind: controller.DependencyWeak,
Kind: controller.InputWeak,
},
}
}

// Outputs implements controller.Controller interface.
func (ctrl *MachineTypeController) Outputs() []controller.Output {
return []controller.Output{
{
Type: config.MachineTypeType,
Kind: controller.OutputExclusive,
},
}); err != nil {
return fmt.Errorf("error setting up dependencies: %w", err)
}
}

// Run implements controller.Controller interface.
func (ctrl *MachineTypeController) Run(ctx context.Context, r controller.Runtime, logger *log.Logger) error {
for {
select {
case <-ctx.Done():
Expand All @@ -62,7 +68,7 @@ func (ctrl *MachineTypeController) Run(ctx context.Context, r controller.Runtime
machineType = cfg.(*config.MachineConfig).Config().Machine().Type()
}

if err = r.Update(ctx, config.NewMachineType(), func(r resource.Resource) error {
if err = r.Modify(ctx, config.NewMachineType(), func(r resource.Resource) error {
r.(*config.MachineType).SetMachineType(machineType)

return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,37 @@ func (ctrl *ControlPlaneStaticPodController) Name() string {
return "k8s.ControlPlaneStaticPodController"
}

// ManagedResources implements controller.Controller interface.
func (ctrl *ControlPlaneStaticPodController) ManagedResources() (resource.Namespace, resource.Type) {
return k8s.ControlPlaneNamespaceName, k8s.StaticPodType
}

// Run implements controller.Controller interface.
//
//nolint:gocyclo
func (ctrl *ControlPlaneStaticPodController) Run(ctx context.Context, r controller.Runtime, logger *log.Logger) error {
if err := r.UpdateDependencies([]controller.Dependency{
// Inputs implements controller.Controller interface.
func (ctrl *ControlPlaneStaticPodController) Inputs() []controller.Input {
return []controller.Input{
{
Namespace: config.NamespaceName,
Type: config.K8sControlPlaneType,
Kind: controller.DependencyWeak,
Kind: controller.InputWeak,
},
{
Namespace: k8s.ControlPlaneNamespaceName,
Type: k8s.SecretsStatusType,
ID: pointer.ToString(k8s.StaticPodSecretsStaticPodID),
Kind: controller.DependencyWeak,
Kind: controller.InputWeak,
},
}
}

// Outputs implements controller.Controller interface.
func (ctrl *ControlPlaneStaticPodController) Outputs() []controller.Output {
return []controller.Output{
{
Type: k8s.StaticPodType,
Kind: controller.OutputExclusive,
},
}); err != nil {
return fmt.Errorf("error setting up dependencies: %w", err)
}
}

// Run implements controller.Controller interface.
//
//nolint:gocyclo
func (ctrl *ControlPlaneStaticPodController) Run(ctx context.Context, r controller.Runtime, logger *log.Logger) error {
for {
select {
case <-ctx.Done():
Expand Down Expand Up @@ -214,7 +220,7 @@ func (ctrl *ControlPlaneStaticPodController) manageAPIServer(ctx context.Context
args = append(args, fmt.Sprintf("--%s=%s", k, v))
}

return r.Update(ctx, k8s.NewStaticPod(k8s.ControlPlaneNamespaceName, "kube-apiserver", nil), func(r resource.Resource) error {
return r.Modify(ctx, k8s.NewStaticPod(k8s.ControlPlaneNamespaceName, "kube-apiserver", nil), func(r resource.Resource) error {
r.(*k8s.StaticPod).SetPod(&v1.Pod{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Expand Down Expand Up @@ -308,7 +314,7 @@ func (ctrl *ControlPlaneStaticPodController) manageControllerManager(ctx context
}

//nolint:dupl
return r.Update(ctx, k8s.NewStaticPod(k8s.ControlPlaneNamespaceName, "kube-controller-manager", nil), func(r resource.Resource) error {
return r.Modify(ctx, k8s.NewStaticPod(k8s.ControlPlaneNamespaceName, "kube-controller-manager", nil), func(r resource.Resource) error {
r.(*k8s.StaticPod).SetPod(&v1.Pod{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Expand Down Expand Up @@ -390,7 +396,7 @@ func (ctrl *ControlPlaneStaticPodController) manageScheduler(ctx context.Context
}

//nolint:dupl
return r.Update(ctx, k8s.NewStaticPod(k8s.ControlPlaneNamespaceName, "kube-scheduler", nil), func(r resource.Resource) error {
return r.Modify(ctx, k8s.NewStaticPod(k8s.ControlPlaneNamespaceName, "kube-scheduler", nil), func(r resource.Resource) error {
r.(*k8s.StaticPod).SetPod(&v1.Pod{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Expand Down
Loading

0 comments on commit fbfd1eb

Please sign in to comment.