Skip to content

Commit

Permalink
Merge pull request #56 from phillipsj/feature/adding-system-agent-sup…
Browse files Browse the repository at this point in the history
…port

Adding system agent support
  • Loading branch information
phillipsj authored Oct 5, 2021
2 parents bb5b8f6 + 7bdb902 commit e046a4f
Show file tree
Hide file tree
Showing 12 changed files with 872 additions and 23 deletions.
1 change: 1 addition & 0 deletions .adr-dir
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docs/adrs
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,21 @@ OPTIONS:
> curl.exe 127.0.0.1
```

#### Enabling System Agent functionality

The system agent functionality will only be enabled if the configuration section for the system agent is found in the config file. To enable it, provide the following configuration section with the required settings. If *remoteEnabled* is set to `true` then connectionInfoFile will need to be configured.

```YAML
systemagent:
appliedPlanDirectory: <agent dir>/applied
connectionInfoFile: <agent dir>/connection.yaml
localEnabled: <bool>
localPlanDirectory: <agent dir>/plans
preserveWorkDirectory: <bool>
remoteEnabled: <bool>
workDirectory: <agent dir>/work
```
## Build
``` powershell
> .\make build
Expand Down
5 changes: 4 additions & 1 deletion cmd/server/app/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/rancher/wins/pkg/defaults"
"github.com/rancher/wins/pkg/panics"
"github.com/rancher/wins/pkg/profilings"
"github.com/rancher/wins/pkg/systemagent"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
"google.golang.org/grpc"
Expand Down Expand Up @@ -104,7 +105,9 @@ func _runAction(cliCtx *cli.Context) error {
if err != nil {
return errors.Wrapf(err, "failed to create server")
}
err = runService(ctx, server)
agent := systemagent.New(cfg.SystemAgent)

err = runService(ctx, server, agent)
if err != nil {
return errors.Wrapf(err, "failed to run server")
}
Expand Down
10 changes: 9 additions & 1 deletion cmd/server/app/run_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/rancher/wins/pkg/logs"
"github.com/rancher/wins/pkg/paths"
"github.com/rancher/wins/pkg/profilings"
"github.com/rancher/wins/pkg/systemagent"
"github.com/sirupsen/logrus"
"golang.org/x/sys/windows"
"golang.org/x/sys/windows/svc"
Expand Down Expand Up @@ -165,7 +166,7 @@ func unregisterService() error {
return nil
}

func runService(ctx context.Context, server *apis.Server) error {
func runService(ctx context.Context, server *apis.Server, agent *systemagent.Agent) error {
// If the process is not currently executing as a Windows service, assume that this is an interactive session.
// debug.Run runs the binary that the service points to directly on the user's console and reacts to user actions
// e.g. clicking on Ctrl-C
Expand Down Expand Up @@ -207,6 +208,7 @@ func runService(ctx context.Context, server *apis.Server) error {
doneC: make(chan struct{}),
errC: make(chan error),
srv: server,
agent: agent,
}
go func() {
h.errC <- run(defaults.WindowsServiceName, h)
Expand All @@ -229,6 +231,7 @@ type serviceHandler struct {
doneC chan struct{}
errC chan error
srv *apis.Server
agent *systemagent.Agent
}

func (h *serviceHandler) Execute(_ []string, r <-chan svc.ChangeRequest, s chan<- svc.Status) (bool, uint32) {
Expand All @@ -241,6 +244,11 @@ func (h *serviceHandler) Execute(_ []string, r <-chan svc.ChangeRequest, s chan<
h.errC <- h.srv.Serve(ctx)
}()

// start system agent
go func() {
h.errC <- h.agent.Run(ctx)
}()

s <- svc.Status{State: svc.Running, Accepts: svc.AcceptStop | svc.AcceptShutdown | svc.AcceptParamChange}

// The following loop configures the Windows service to respond to ChangeRequests from the Windows Service Manager
Expand Down
12 changes: 7 additions & 5 deletions cmd/server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/ghodss/yaml"
"github.com/pkg/errors"
"github.com/rancher/system-agent/pkg/config"
"github.com/rancher/wins/pkg/defaults"
)

Expand All @@ -26,11 +27,12 @@ func DefaultConfig() *Config {
}

type Config struct {
Debug bool `yaml:"debug" json:"debug"`
Listen string `yaml:"listen" json:"listen"`
Proxy string `yaml:"proxy" json:"proxy"`
WhiteList WhiteListConfig `yaml:"white_list" json:"white_list"`
Upgrade UpgradeConfig `yaml:"upgrade" json:"upgrade"`
Debug bool `yaml:"debug" json:"debug"`
Listen string `yaml:"listen" json:"listen"`
Proxy string `yaml:"proxy" json:"proxy"`
WhiteList WhiteListConfig `yaml:"white_list" json:"white_list"`
Upgrade UpgradeConfig `yaml:"upgrade" json:"upgrade"`
SystemAgent *config.AgentConfig `yaml:"systemagent" json:"systemagent"`
}

func (c *Config) Validate() error {
Expand Down
19 changes: 19 additions & 0 deletions docs/adrs/0001-record-architecture-decisions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 1. Record architecture decisions

Date: 2021-10-04

## Status

Accepted

## Context

We need to record the architectural decisions made on this project.

## Decision

We will use Architecture Decision Records, as [described by Michael Nygard](http://thinkrelevance.com/blog/2011/11/15/documenting-architecture-decisions).

## Consequences

See Michael Nygard's article, linked above. For a lightweight ADR toolset, see Nat Pryce's [adr-tools](https://github.com/npryce/adr-tools).
19 changes: 19 additions & 0 deletions docs/adrs/0002-add-system-agent-support-to-wins.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 2. Add System Agent support to Wins

Date: 2021-10-04

## Status

Accepted

## Context

Currently, RKE2 uses [`rancher/system-agent`](https://github.com/rancher/system-agent) to install and upgrade RKE2 using plans. However, this capability doesn't currently exist for Windows hosts. System Agent functionality needs some capabilities of Wins to achieve its goal. This would require that both the system agent service and wins service to be running on a system. Alternatively, we could consume the system agent as a package in the wins service reducing the need to having both installed in a system.

## Decision

The decision was to consume the system agent functionality as a package in wins.

## Consequences

This decision reduces the overall services running on a system and allows leveraging the existing wins upgrader and capabilities to provide the system agent functionality.
19 changes: 19 additions & 0 deletions docs/adrs/0003-system-agent-configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 3. System Agent configuration

Date: 2021-10-04

## Status

Accepted

## Context

The system agent requires some configuration. In addition, wins need the ability to enable or disable the system agent functionality to enable backwards compatibility.

## Decision

Two decisions were made. The system agent functionality was added to the wins configuration file as a section called *sa*. The second decision is that if that section doesn't exist, then system agent functionality will be disabled. If, it does exist, then the system agent functionality will be enabled.

## Consequences

This allows maintaining consistent behavior for existing users. Users will not need any additional command line options to alter the behavior. This does require that users of system agent know that the configuration is required. The primary user currently will be Rancher and therefore, will set the configuration correctly during install.
39 changes: 32 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,34 @@
module github.com/rancher/wins

go 1.15
go 1.16

replace (
k8s.io/api => k8s.io/api v0.21.0
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.21.0
k8s.io/apimachinery => k8s.io/apimachinery v0.21.0
k8s.io/apiserver => k8s.io/apiserver v0.21.0
k8s.io/cli-runtime => k8s.io/cli-runtime v0.21.0
k8s.io/client-go => github.com/rancher/client-go v0.21.0-rancher.1
k8s.io/cloud-provider => k8s.io/cloud-provider v0.21.0
k8s.io/cluster-bootstrap => k8s.io/cluster-bootstrap v0.21.0
k8s.io/code-generator => k8s.io/code-generator v0.21.0
k8s.io/component-base => k8s.io/component-base v0.21.0
k8s.io/component-helpers => k8s.io/component-helpers v0.21.0
k8s.io/controller-manager => k8s.io/controller-manager v0.21.0
k8s.io/cri-api => k8s.io/cri-api v0.21.0
k8s.io/csi-translation-lib => k8s.io/csi-translation-lib v0.21.0
k8s.io/kube-aggregator => k8s.io/kube-aggregator v0.21.0
k8s.io/kube-controller-manager => k8s.io/kube-controller-manager v0.21.0
k8s.io/kube-proxy => k8s.io/kube-proxy v0.21.0
k8s.io/kube-scheduler => k8s.io/kube-scheduler v0.21.0
k8s.io/kubectl => k8s.io/kubectl v0.21.0
k8s.io/kubelet => k8s.io/kubelet v0.21.0
k8s.io/kubernetes => k8s.io/kubernetes v1.21.0
k8s.io/legacy-cloud-providers => k8s.io/legacy-cloud-providers v0.21.0
k8s.io/metrics => k8s.io/metrics v0.21.0
k8s.io/mount-utils => k8s.io/mount-utils v0.21.0
k8s.io/sample-apiserver => k8s.io/sample-apiserver v0.21.0
)

require (
github.com/Microsoft/go-winio v0.4.16
Expand All @@ -10,29 +38,26 @@ require (
github.com/fsnotify/fsnotify v1.4.9
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32
github.com/gogo/protobuf v1.3.2
github.com/google/go-cmp v0.5.4 // indirect
github.com/gorilla/websocket v1.4.2
github.com/grpc-ecosystem/go-grpc-middleware v1.2.2
github.com/hashicorp/go-multierror v1.0.0
github.com/kr/text v0.2.0 // indirect
github.com/mattn/go-colorable v0.1.8
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.9.0 // indirect
github.com/prometheus/procfs v0.5.0 // indirect
github.com/rancher/remotedialer v0.2.6-0.20201012155453-8b1b7bb7d05f
github.com/rancher/system-agent v0.1.0
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sirupsen/logrus v1.7.0
github.com/sirupsen/logrus v1.8.1
github.com/stretchr/testify v1.7.0 // indirect
github.com/urfave/cli v1.22.5
go.opencensus.io v0.22.6 // indirect
golang.org/x/net v0.0.0-20210119194325-5f4716e94777 // indirect
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c
golang.org/x/sys v0.0.0-20210225134936-a50acf3fe073
golang.org/x/text v0.3.5 // indirect
google.golang.org/genproto v0.0.0-20210207032614-bba0dbe2a9ea // indirect
google.golang.org/grpc v1.35.0
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
inet.af/tcpproxy v0.0.0-20200125044825-b6bb9b5b8252
)
Loading

0 comments on commit e046a4f

Please sign in to comment.