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

Commit

Permalink
Add linkerd implementions
Browse files Browse the repository at this point in the history
  • Loading branch information
Daishan committed Sep 13, 2019
1 parent 2f4613a commit cd3a79e
Show file tree
Hide file tree
Showing 81 changed files with 1,848 additions and 1,158 deletions.
1 change: 1 addition & 0 deletions cli/cmd/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type Create struct {
DNSOption []string `desc:"Set DNS options (format: key:value or key)"`
DNSSearch []string `desc:"Set custom DNS search domains"`
DNS []string `desc:"Set custom DNS servers"`
DisableServiceMesh bool `desc:"Disable service mesh"`
E_Env []string `desc:"Set environment variables"`
EnvFile []string `desc:"Read in a file of environment variables"`
GlobalPermission []string `desc:"Permissions to grant to container's service account for all namespaces"`
Expand Down
6 changes: 4 additions & 2 deletions cli/cmd/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ type Install struct {
DisableFeatures []string `desc:"Manually specify features to disable, supports comma separated values"`
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'"`
Check bool `desc:"Only check status, don't deploy controller"`
Lite bool `desc:"Only install lite version of Rio(monitoring will be disabled, will be ignored if --disable-features is set)"`
Mode string `desc:"Install mode to expose gateway. Available options are ingress, svclb and hostport" default:"ingress"`
MeshMode string `desc:"Service mesh mode. Options: (linkerd/istio)" default:"linkerd"`
}

func (i *Install) Run(ctx *clicontext.CLIContext) error {
Expand Down Expand Up @@ -168,6 +169,7 @@ func (i *Install) Run(ctx *clicontext.CLIContext) error {
"SERVICE_CIDR": i.ServiceCidr,
"DISABLE_FEATURES": strings.Join(i.DisableFeatures, ","),
"HTTP_PROXY": i.HTTPProxy,
"SM_MODE": i.MeshMode,
}
if i.Yaml {
yamlOutput, err := controllerStack.Yaml(answers)
Expand Down Expand Up @@ -332,7 +334,7 @@ func (i *Install) fallbackInstall(ctx *clicontext.CLIContext, info *adminv1.RioI
}

if i.Mode == constants.InstallModeSvclb {
svc, err := ctx.Core.Services(info.Status.SystemNamespace).Get(fmt.Sprintf("%s-%s", constants.IstioGateway, constants.DefaultServiceVersion), metav1.GetOptions{})
svc, err := ctx.Core.Services(info.Status.SystemNamespace).Get(fmt.Sprintf("%s-%s", constants.GatewayName, constants.DefaultServiceVersion), metav1.GetOptions{})
if err != nil {
return false, err
}
Expand Down
2 changes: 1 addition & 1 deletion cli/pkg/tables/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func formatAppDetail(obj interface{}) (string, error) {
}

rev := versions[name]
if !rev.DeploymentReady && (svc.Revision.SystemSpec == nil || !svc.Revision.SystemSpec.Global) {
if !rev.DeploymentReady && !svc.Revision.Spec.Global {
if buffer.Len() > 0 {
buffer.WriteString("; ")
}
Expand Down
7 changes: 7 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ func main() {
Value: "10.43.0.0/16",
Destination: &constants.ServiceCidr,
},
cli.StringFlag{
Name: "service-mesh-mode",
Usage: "Specify service mesh mode",
EnvVar: "SM_MODE",
Value: constants.ServiceMeshMode,
Destination: &constants.ServiceMeshMode,
},
cli.StringFlag{
Name: "disable-features",
Usage: "Manually specify features to disable",
Expand Down
7 changes: 6 additions & 1 deletion modules/autoscale/controller/service/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
servingv1beta1 "github.com/knative/serving/pkg/apis/serving/v1beta1"
autoscalev1 "github.com/rancher/rio/pkg/apis/autoscale.rio.cattle.io/v1"
v1 "github.com/rancher/rio/pkg/apis/rio.cattle.io/v1"
"github.com/rancher/rio/pkg/constants"
"github.com/rancher/rio/pkg/constructors"
autoscalev1controller "github.com/rancher/rio/pkg/generated/controllers/autoscale.rio.cattle.io/v1"
riov1controller "github.com/rancher/rio/pkg/generated/controllers/rio.cattle.io/v1"
Expand Down Expand Up @@ -148,7 +149,11 @@ func populatePodAutoscaler(object runtime.Object, ns *corev1.Namespace, os *obje
ReferingLabel: "kpa.autoscaling.knative.dev",
MinScaleAnnotationKey: strconv.Itoa(*service.Spec.MinScale),
MaxScaleAnnotationKey: strconv.Itoa(*service.Spec.MaxScale),
ScrapeKey: "envoy",
}
if constants.ServiceMeshMode == constants.ServiceMeshModeLinkerd {
annotation[ScrapeKey] = "linkerd"
} else if constants.ServiceMeshMode == constants.ServiceMeshModeIstio {
annotation[ScrapeKey] = "envoy"
}
var portValue string
for _, port := range service.Spec.Ports {
Expand Down
10 changes: 8 additions & 2 deletions modules/autoscale/feature/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package feature
import (
"context"

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

"github.com/rancher/rio/modules/autoscale/controller/service"
v1 "github.com/rancher/rio/pkg/apis/admin.rio.cattle.io/v1"
"github.com/rancher/rio/pkg/constants"
"github.com/rancher/rio/pkg/features"
"github.com/rancher/rio/pkg/stack"
"github.com/rancher/rio/types"
"github.com/rancher/wrangler/pkg/start"
)

func Register(ctx context.Context, rContext *types.Context) error {
Expand All @@ -29,6 +29,12 @@ func Register(ctx context.Context, rContext *types.Context) error {
Controllers: []features.ControllerRegister{
service.Register,
},
OnStart: func(feature *v1.Feature) error {
return start.All(ctx, 5,
rContext.Serving,
rContext.AutoScale,
)
},
}
return feature.Register()
}
7 changes: 7 additions & 0 deletions modules/build/feature/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/rancher/rio/pkg/features"
"github.com/rancher/rio/pkg/stack"
"github.com/rancher/rio/types"
"github.com/rancher/wrangler/pkg/start"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -55,6 +56,12 @@ func Register(ctx context.Context, rContext *types.Context) error {
"RUNTIME": runtime,
"SOCKET_ADDRESS": socket,
},
OnStart: func(feature *v1.Feature) error {
return start.All(ctx, 5,
rContext.Build,
rContext.Webhook,
)
},
}
return feature.Register()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"sort"

"github.com/knative/pkg/apis/istio/v1alpha3"
"github.com/rancher/rio/modules/istio/controllers/service/populate"
"github.com/rancher/rio/modules/gateway/controllers/service/populate"
riov1 "github.com/rancher/rio/pkg/apis/rio.cattle.io/v1"
"github.com/rancher/rio/pkg/constants"
"github.com/rancher/rio/pkg/constructors"
Expand Down Expand Up @@ -105,10 +105,6 @@ func (s serviceHandler) populate(obj runtime.Object, namespace *corev1.Namespace
revVs := populate.VirtualServiceFromSpec(true, s.systemNamespace, app.Name, app.Namespace, clusterDomain, deepcopy, dests...)
os.Add(revVs)

if clusterDomain.Status.ClusterDomain != "" && constants.InstallMode == constants.InstallModeIngress {
populate.Ingress(s.systemNamespace, clusterDomain.Status.ClusterDomain, clusterDomain.Spec.SecretRef.Name, true, revision, os)
}

return nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package externalservice
import (
"context"

"github.com/rancher/rio/modules/istio/controllers/externalservice/populate"
populate "github.com/rancher/rio/modules/gateway/controllers/externalservice/populate"
riov1 "github.com/rancher/rio/pkg/apis/rio.cattle.io/v1"
"github.com/rancher/rio/pkg/constants"
v12 "github.com/rancher/rio/pkg/generated/controllers/admin.rio.cattle.io/v1"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package populate

import (
"github.com/rancher/rio/modules/istio/controllers/service/populate"
"github.com/rancher/rio/modules/gateway/controllers/service/populate"
v1 "github.com/rancher/rio/pkg/apis/admin.rio.cattle.io/v1"
riov1 "github.com/rancher/rio/pkg/apis/rio.cattle.io/v1"
"github.com/rancher/rio/pkg/serviceset"
Expand Down
69 changes: 69 additions & 0 deletions modules/gateway/controllers/istio/controller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package istio

import (
"context"
"fmt"

"github.com/rancher/rio/modules/gateway/controllers/istio/populate"
adminv1 "github.com/rancher/rio/pkg/apis/admin.rio.cattle.io/v1"
"github.com/rancher/rio/pkg/constants"
adminv1controller "github.com/rancher/rio/pkg/generated/controllers/admin.rio.cattle.io/v1"
"github.com/rancher/rio/types"
"github.com/rancher/wrangler/pkg/apply"
"github.com/rancher/wrangler/pkg/objectset"
"github.com/rancher/wrangler/pkg/trigger"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/labels"
)

const (
istioStack = "istio-stack"
)

var (
addressTypes = []v1.NodeAddressType{
v1.NodeExternalIP,
v1.NodeInternalIP,
}

evalTrigger trigger.Trigger
)

func Register(ctx context.Context, rContext *types.Context) error {
s := &istioDeployController{
namespace: rContext.Namespace,
gatewayApply: rContext.Apply.WithSetID(istioStack).WithStrictCaching().
WithCacheTypes(rContext.Networking.Networking().V1alpha3().Gateway()),
publicDomainCache: rContext.Global.Admin().V1().PublicDomain().Cache(),
}

rContext.Global.Admin().V1().ClusterDomain().OnChange(ctx, "clusterdomain-gateway", s.syncGateway)

return nil
}

type istioDeployController struct {
namespace string
gatewayApply apply.Apply
publicDomainCache adminv1controller.PublicDomainCache
}

func (i istioDeployController) syncGateway(key string, obj *adminv1.ClusterDomain) (*adminv1.ClusterDomain, error) {
if obj == nil || obj.DeletionTimestamp != nil || obj.Name != constants.ClusterDomainName {
return obj, nil
}

os := objectset.NewObjectSet()
domain := ""
if obj.Status.ClusterDomain != "" {
domain = fmt.Sprintf("*.%s", obj.Status.ClusterDomain)
}

publicdomains, err := i.publicDomainCache.List("", labels.NewSelector())
if err != nil {
return obj, err
}
populate.Gateway(i.namespace, domain, obj.Spec.SecretRef.Name, publicdomains, os)

return obj, i.gatewayApply.Apply(os)
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func Gateway(systemNamespace, clusterDomain, certName string, publicdomains []*v
// Istio Gateway
gws := v1alpha3.GatewaySpec{
Selector: map[string]string{
"app": constants.IstioGateway,
"app": constants.GatewayName,
},
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestGatewayWithoutPublicdomains(t *testing.T) {
expected := constructors.NewGateway(systemNs, constants.RioGateway, v1alpha3.Gateway{
Spec: v1alpha3.GatewaySpec{
Selector: map[string]string{
"app": constants.IstioGateway,
"app": constants.GatewayName,
},
Servers: []v1alpha3.Server{
{
Expand Down Expand Up @@ -81,7 +81,7 @@ func TestGatewayWithPublicdomains(t *testing.T) {
expected := constructors.NewGateway(systemNs, constants.RioGateway, v1alpha3.Gateway{
Spec: v1alpha3.GatewaySpec{
Selector: map[string]string{
"app": constants.IstioGateway,
"app": constants.GatewayName,
},
Servers: []v1alpha3.Server{
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ package publicdomain
import (
"context"

"github.com/rancher/rio/modules/istio/controllers/publicdomain/populate"
"github.com/rancher/rio/modules/gateway/controllers/publicdomain/populate"
adminv1 "github.com/rancher/rio/pkg/apis/admin.rio.cattle.io/v1"
"github.com/rancher/rio/pkg/constants"
"github.com/rancher/rio/pkg/stackobject"
"github.com/rancher/rio/types"
"github.com/rancher/wrangler/pkg/objectset"
Expand All @@ -15,8 +14,7 @@ import (

func Register(ctx context.Context, rContext *types.Context) error {
c := stackobject.NewGeneratingController(ctx, rContext, "routing-publicdomain", rContext.Global.Admin().V1().PublicDomain())
c.Apply = c.Apply.WithCacheTypes(rContext.Networking.Networking().V1alpha3().DestinationRule(),
rContext.K8sNetworking.Networking().V1beta1().Ingress())
c.Apply = c.Apply.WithCacheTypes(rContext.Networking.Networking().V1alpha3().DestinationRule())
p := populator{
systemNamespace: rContext.Namespace,
}
Expand All @@ -30,9 +28,6 @@ type populator struct {

func (p populator) populate(obj runtime.Object, ns *corev1.Namespace, os *objectset.ObjectSet) error {
pd := obj.(*adminv1.PublicDomain)
if constants.InstallMode == constants.InstallModeIngress {
populate.Ingress(p.systemNamespace, pd, os)
}
populate.DestionationRule(obj.(*adminv1.PublicDomain), p.systemNamespace, os)
populate.DestionationRule(pd, p.systemNamespace, os)
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,28 @@ package routeset

import (
"context"
"fmt"

"github.com/rancher/rio/modules/istio/controllers/routeset/populate"
"github.com/rancher/rio/modules/istio/pkg/domains"
"github.com/rancher/rio/modules/istio/pkg/parse"
adminv1 "github.com/rancher/rio/pkg/apis/admin.rio.cattle.io/v1"
"github.com/rancher/rio/modules/gateway/controllers/routeset/populate"
riov1 "github.com/rancher/rio/pkg/apis/rio.cattle.io/v1"
"github.com/rancher/rio/pkg/constants"
projectv1controller "github.com/rancher/rio/pkg/generated/controllers/admin.rio.cattle.io/v1"
riov1controller "github.com/rancher/rio/pkg/generated/controllers/rio.cattle.io/v1"
"github.com/rancher/rio/pkg/stackobject"
"github.com/rancher/rio/types"
corev1controller "github.com/rancher/wrangler-api/pkg/generated/controllers/core/v1"
"github.com/rancher/wrangler/pkg/generic"
"github.com/rancher/wrangler/pkg/objectset"
"github.com/rancher/wrangler/pkg/relatedresource"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
)

const (
routerDomainUpdate = "router-domain-updater"
)

func Register(ctx context.Context, rContext *types.Context) error {
c := stackobject.NewGeneratingController(ctx, rContext, "routing-routeset", rContext.Rio.Rio().V1().Router())
c.Apply = c.Apply.WithStrictCaching().
WithCacheTypes(rContext.Networking.Networking().V1alpha3().VirtualService(),
rContext.Networking.Networking().V1alpha3().DestinationRule(),
rContext.Networking.Networking().V1alpha3().ServiceEntry(),
rContext.K8sNetworking.Networking().V1beta1().Ingress())
rContext.Networking.Networking().V1alpha3().ServiceEntry())

r := &routeSetHandler{
systemNamespace: rContext.Namespace,
Expand All @@ -43,8 +33,6 @@ func Register(ctx context.Context, rContext *types.Context) error {
clusterDomainCache: rContext.Global.Admin().V1().ClusterDomain().Cache(),
}

rContext.Rio.Rio().V1().Router().AddGenericHandler(ctx, routerDomainUpdate, generic.UpdateOnChange(rContext.Rio.Rio().V1().Router().Updater(), r.syncDomain))

relatedresource.Watch(ctx, "externalservice-routeset", r.resolve,
rContext.Rio.Rio().V1().Router(), rContext.Rio.Rio().V1().ExternalService())

Expand Down Expand Up @@ -110,38 +98,5 @@ func (r *routeSetHandler) populate(obj runtime.Object, ns *corev1.Namespace, os
return err
}

if constants.InstallMode == constants.InstallModeIngress {
populate.Ingress(r.systemNamespace, domain, clusterDomain.Spec.SecretRef.Name, routeSet, os)
}

return nil
}

func (r *routeSetHandler) syncDomain(key string, obj runtime.Object) (runtime.Object, error) {
if obj == nil {
return nil, nil
}

clusterDomain, err := r.clusterDomainCache.Get(r.systemNamespace, constants.ClusterDomainName)
if err != nil {
return obj, err
}

updateDomain(obj.(*riov1.Router), clusterDomain)

return obj, nil
}

func updateDomain(router *riov1.Router, clusterDomain *adminv1.ClusterDomain) {
protocol := "http"
if clusterDomain.Status.HTTPSSupported {
protocol = "https"
}
router.Status.Endpoints = []string{
fmt.Sprintf("%s://%s", protocol, domains.GetExternalDomain(router.Name, router.Namespace, clusterDomain.Status.ClusterDomain)),
}
for _, pd := range router.Status.PublicDomains {
router.Status.Endpoints = append(router.Status.Endpoints, fmt.Sprintf("%s://%s", protocol, pd))
}
router.Status.Endpoints = parse.FormatEndpoint(protocol, router.Status.Endpoints)
}
Loading

0 comments on commit cd3a79e

Please sign in to comment.