Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
Cleaning up code
Browse files Browse the repository at this point in the history
1. remove devMode, move proper arguments to controller
2. move linkerd-job to a stack
3. split rio-controller into controller and  bootstrap stack
  • Loading branch information
Daishan committed Nov 11, 2019
1 parent dec9ef3 commit e8b6c26
Show file tree
Hide file tree
Showing 23 changed files with 710 additions and 707 deletions.
8 changes: 4 additions & 4 deletions cli/cmd/builds/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"io/ioutil"
"path/filepath"

"github.com/rancher/rio/cli/cmd/up/pkg"
"github.com/rancher/rio/cli/pkg/builder"
"github.com/rancher/rio/cli/pkg/clicontext"
"github.com/rancher/rio/cli/pkg/up"
riov1 "github.com/rancher/rio/pkg/apis/rio.cattle.io/v1"
"github.com/rancher/rio/pkg/stack"
"github.com/urfave/cli"
Expand Down Expand Up @@ -37,12 +37,12 @@ type Build struct {
}

func (b *Build) Run(ctx *clicontext.CLIContext) error {
content, err := pkg.LoadRiofile(b.F_File)
content, err := up.LoadRiofile(b.F_File)
if err != nil {
return err
}

answers, err := pkg.LoadAnswer("")
answers, err := up.LoadAnswer("")
if err != nil {
return err
}
Expand All @@ -57,7 +57,7 @@ func (b *Build) Run(ctx *clicontext.CLIContext) error {
return err
}

images, err := pkg.Build(imageBuilds, ctx, false)
images, err := up.Build(imageBuilds, ctx, false)
if err != nil {
return err
}
Expand Down
23 changes: 16 additions & 7 deletions cli/cmd/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ type Install struct {
IPAddress []string `desc:"Manually specify IP addresses to generate rdns domain, supports comma separated values" name:"ip-address"`
DisableFeatures []string `desc:"Manually specify features to disable, supports comma separated values"`
EnableDebug bool `desc:"Enable debug logging in controller"`
HTTPProxy string `desc:"Set HTTP_PROXY environment variable for control plane"`
Yaml bool `desc:"Only print out k8s yaml manifest"`
Check bool `desc:"Only check status, don't deploy controller"`
}
Expand All @@ -39,23 +38,30 @@ func (i *Install) Run(ctx *clicontext.CLIContext) error {
}

namespace := ctx.SystemNamespace
bootstrapStack := stack.NewSystemStack(ctx.Apply, nil, namespace, "rio-bootstrap")
controllerStack := stack.NewSystemStack(ctx.Apply, nil, namespace, "rio-controller")

answers := map[string]string{
"NAMESPACE": namespace,
"DEBUG": strconv.FormatBool(i.EnableDebug),
"IMAGE": fmt.Sprintf("%s:%s", constants.ControllerImage, constants.ControllerImageTag),
"HTTP_PROXY": i.HTTPProxy,
"RUN_CONTROLLER": "true",
"NAMESPACE": namespace,
"RIO_DEBUG": strconv.FormatBool(i.EnableDebug),
"IMAGE": fmt.Sprintf("%s:%s", constants.ControllerImage, constants.ControllerImageTag),
"RUN_API_VALIDATOR": "\"TRUE\"",
}
bootstrapStack.WithAnswer(answers)
controllerStack.WithAnswer(answers)

if i.Yaml {
bootstrapObjects, err := bootstrapStack.GetObjects()
if err != nil {
return err
}

cm, err := i.getConfigMap(ctx, true)
if err != nil {
return err
}

yamlOutput, err := controllerStack.Yaml(answers, cm)
yamlOutput, err := controllerStack.Yaml(nil, append(bootstrapObjects, cm)...)
if err != nil {
return err
}
Expand All @@ -79,6 +85,9 @@ func (i *Install) Run(ctx *clicontext.CLIContext) error {
}

fmt.Println("Deploying Rio control plane....")
if err := bootstrapStack.Deploy(answers); err != nil {
return err
}
if err := controllerStack.Deploy(answers, cm); err != nil {
return err
}
Expand Down
20 changes: 14 additions & 6 deletions cli/cmd/up/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package up
import (
"fmt"

"github.com/rancher/rio/cli/cmd/up/pkg"
"github.com/rancher/rio/cli/pkg/clicontext"
"github.com/rancher/rio/cli/pkg/up"
riov1 "github.com/rancher/rio/pkg/apis/rio.cattle.io/v1"
"github.com/rancher/rio/pkg/riofile/stringers"
"github.com/rancher/rio/pkg/stack"
Expand Down Expand Up @@ -33,7 +33,7 @@ const (

func (u *Up) Run(c *clicontext.CLIContext) error {
if u.Name == "" {
u.Name = pkg.GetCurrentDir()
u.Name = up.GetCurrentDir()
}

stack, err := u.ensureStack(c)
Expand Down Expand Up @@ -103,12 +103,12 @@ func (u *Up) setBuild(c *clicontext.CLIContext) error {
}

func (u *Up) loadFileAndAnswer(c *clicontext.CLIContext) (string, map[string]string, error) {
answers, err := pkg.LoadAnswer(u.Answers)
answers, err := up.LoadAnswer(u.Answers)
if err != nil {
return "", nil, err
}

content, err := pkg.LoadRiofile(u.F_File)
content, err := up.LoadRiofile(u.F_File)
if err != nil {
return "", nil, err
}
Expand All @@ -122,7 +122,7 @@ func (u *Up) up(content string, answers map[string]string, s *riov1.Stack, c *cl
return err
}

images, err := pkg.Build(imageBuilds, c, u.P_Parallel)
images, err := up.Build(imageBuilds, c, u.P_Parallel)
if err != nil {
return err
}
Expand Down Expand Up @@ -151,7 +151,15 @@ func (u *Up) up(content string, answers map[string]string, s *riov1.Stack, c *cl
knowngvks = s.Spec.AdditionalGroupVersionKinds
}

err = c.Apply.WithListerNamespace(c.GetSetNamespace()).WithDefaultNamespace(c.GetSetNamespace()).WithOwner(s).WithSetOwnerReference(true, true).WithGVK(knowngvks...).WithDynamicLookup().ApplyObjects(objs...)
err = c.Apply.
WithListerNamespace(c.GetSetNamespace()).
WithDefaultNamespace(c.GetSetNamespace()).
WithOwner(s).
WithSetOwnerReference(true, true).
WithGVK(knowngvks...).
WithRestrictClusterScoped().
WithDynamicLookup().
ApplyObjects(objs...)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/up/pkg/build.go → cli/pkg/up/build.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pkg
package up

import (
"fmt"
Expand Down
27 changes: 26 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:generate go run pkg/codegen/cleanup/main.go
//go:generate go run ./vendor/github.com/go-bindata/go-bindata/go-bindata -o ./stacks/bindata.go -ignore bindata.go -pkg stacks -modtime 1557785965 -mode 0644 ./stacks/
//go:generate go run ./vendor/github.com/go-bindata/go-bindata/go-bindata -tags static -o ./stacks/bindata.go -ignore bindata.go -pkg stacks -modtime 1557785965 -mode 0644 ./stacks/
//go:generate go fmt stacks/bindata.go
//go:generate go run pkg/codegen/main.go

Expand All @@ -12,6 +12,8 @@ import (
_ "net/http/pprof"
"os"

"github.com/rancher/rio/pkg/config"

"github.com/rancher/norman/pkg/debug"
"github.com/rancher/rio/pkg/server"
"github.com/rancher/rio/pkg/version"
Expand Down Expand Up @@ -42,6 +44,29 @@ func main() {
Value: "rio-system",
Destination: &namespace,
},
cli.BoolFlag{
Name: "run_api_validator",
Usage: "Whether to run api validator webhook",
EnvVar: "RUN_API_VALIDATOR",
Destination: &config.ConfigController.RunAPIValidatorWebhook,
},
cli.StringFlag{
Name: "webhook_port",
Usage: "Specify which port webhook should listen on",
EnvVar: "RUN_API_VALIDATOR_PORT",
Destination: &config.ConfigController.WebhookPort,
},
cli.StringFlag{
Name: "webhook_host",
Usage: "Specify which host webhook should listen on",
EnvVar: "RUN_API_VALIDATOR_HOST",
Destination: &config.ConfigController.WebhookHost,
},
cli.StringFlag{
Name: "ip_address",
Usage: "Specify which ip address RDNS should generate record for",
Destination: &config.ConfigController.IPAddresses,
},
}
app.Flags = append(app.Flags, debug.Flags(&debugConfig)...)
app.Action = run
Expand Down
22 changes: 21 additions & 1 deletion modules/linkerd/feature/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,42 @@ import (

"github.com/rancher/rio/modules/linkerd/controller/inject"
"github.com/rancher/rio/modules/linkerd/pkg/injector"
"github.com/rancher/rio/pkg/constants"
"github.com/rancher/rio/pkg/features"
"github.com/rancher/rio/pkg/stack"
"github.com/rancher/rio/types"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const (
linkerdNamespace = "linkerd"
linkerdConfigName = "linkerd-config"
)

func Register(ctx context.Context, rContext *types.Context) error {
cmClient := rContext.Core.Core().V1().ConfigMap()
linkerdUpgrade := ""
if _, err := cmClient.Get(linkerdNamespace, linkerdConfigName, metav1.GetOptions{}); err == nil {
linkerdUpgrade = "\"TRUE\""
}
apply := rContext.Apply.WithCacheTypes(rContext.Batch.Batch().V1().Job())
feature := &features.FeatureController{
FeatureName: "linkerd",
FeatureSpec: features.FeatureSpec{
Description: "linkerd service mesh",
Enabled: true,
},
SystemStacks: []*stack.SystemStack{},
SystemStacks: []*stack.SystemStack{
stack.NewSystemStack(apply, rContext.Admin.Admin().V1().SystemStack(), rContext.Namespace, "linkerd-install"),
},
Controllers: []features.ControllerRegister{
inject.Register,
},
FixedAnswers: map[string]string{
"LINKERD_UPGRADE": linkerdUpgrade,
"LINKERD_INSTALL_IMAGE": constants.LinkerdInstallImage,
"NAMESPACE": rContext.Namespace,
},
OnStart: func() error {
injector.RegisterInjector()
rContext.Rio.Rio().V1().Service().Enqueue("*", "*")
Expand Down
50 changes: 0 additions & 50 deletions modules/linkerd/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,59 +4,9 @@ import (
"context"

"github.com/rancher/rio/modules/linkerd/feature"
"github.com/rancher/rio/pkg/constants"
"github.com/rancher/rio/types"
batchv1 "k8s.io/api/batch/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func Register(ctx context.Context, rContext *types.Context) error {
if err := installLinkerd(rContext); err != nil {
return err
}
return feature.Register(ctx, rContext)
}

func installLinkerd(rContext *types.Context) error {
cmClient := rContext.Core.Core().V1().ConfigMap()
linkerdUpgrade := ""
if _, err := cmClient.Get("linkerd", "linkerd-config", metav1.GetOptions{}); err == nil {
linkerdUpgrade = "TRUE"
}
if constants.DevMode && linkerdUpgrade == "TRUE" {
return nil
}

job := &batchv1.Job{
ObjectMeta: metav1.ObjectMeta{
Namespace: rContext.Namespace,
GenerateName: "linkerd-install-",
},
Spec: batchv1.JobSpec{
TTLSecondsAfterFinished: &[]int32{120}[0],
BackoffLimit: &[]int32{1}[0],
Template: v1.PodTemplateSpec{
Spec: v1.PodSpec{
ServiceAccountName: "rio-controller-serviceaccount",
RestartPolicy: v1.RestartPolicyNever,
Containers: []v1.Container{
{
Name: "linkerd-install",
Image: constants.LinkerdInstallImage,
ImagePullPolicy: v1.PullAlways,
Env: []v1.EnvVar{
{
Name: "LINKERD_UPGRADE",
Value: linkerdUpgrade,
},
},
},
},
},
},
},
}
_, err := rContext.Batch.Batch().V1().Job().Create(job)
return err
}
17 changes: 10 additions & 7 deletions modules/rdns/controllers/service/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package service
import (
"context"
"fmt"
"os"
"strings"

approuter "github.com/rancher/rdns-server/client"
adminv1 "github.com/rancher/rio/pkg/apis/admin.rio.cattle.io/v1"
Expand Down Expand Up @@ -159,13 +159,16 @@ func (h *handler) generate(svc *corev1.Service, status corev1.ServiceStatus) ([]
}

func (h *handler) staticAddress() ([]adminv1.Address, error) {
if constants.DevMode && os.Getenv("IP_ADDRESS") != "" {
return []adminv1.Address{
{
IP: os.Getenv("IP_ADDRESS"),
if config.ConfigController.IPAddresses != "" {
ips := strings.Split(config.ConfigController.IPAddresses, ",")
var addresses []adminv1.Address
for _, ip := range ips {
addresses = append(addresses, adminv1.Address{
IP: ip,
Hostname: "",
},
}, nil
})
}
return addresses, nil
}
cm, err := h.configMapCache.Get(h.systemNamespace, config.ConfigName)
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion pkg/apis/admin.rio.cattle.io/v1/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,5 @@ type RioInfoStatus struct {
GitCommit string `json:"gitCommit,omitempty"`
SystemNamespace string `json:"systemNamespace,omitempty"`
Conditions []genericcondition.GenericCondition `json:"conditions,omitempty"`
Ready bool `json:"ready,omitempty"`
SystemComponentReadyMap map[string]string `json:"systemComponentReadyMap,omitempty"`
}
12 changes: 10 additions & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,23 @@ import (
"encoding/json"
"strings"

v1 "k8s.io/api/core/v1"

adminv1 "github.com/rancher/rio/pkg/apis/admin.rio.cattle.io/v1"
v1 "k8s.io/api/core/v1"
)

var (
ConfigName = "rio-config"

ConfigController = ControllerConfig{}
)

type ControllerConfig struct {
RunAPIValidatorWebhook bool
WebhookPort string
WebhookHost string
IPAddresses string
}

type Config struct {
Features map[string]FeatureConfig `json:"features,omitempty"`
LetsEncrypt LetsEncrypt `json:"letsEncrypt,omitempty"`
Expand Down
Loading

0 comments on commit e8b6c26

Please sign in to comment.