Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Istio implementation #341

Merged
merged 10 commits into from
Jan 9, 2020
2 changes: 2 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions cmd/rollouts-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/dynamic"
kubeinformers "k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
Expand All @@ -28,6 +29,8 @@ import (
const (
// CLIName is the name of the CLI
cliName = "argo-rollouts"

defaultIstioVersion = "v1alpha3"
)

func newCommand() *cobra.Command {
Expand All @@ -42,6 +45,7 @@ func newCommand() *cobra.Command {
experimentThreads int
analysisThreads int
serviceThreads int
istioVersion string
)
var command = cobra.Command{
Use: cliName,
Expand Down Expand Up @@ -72,6 +76,8 @@ func newCommand() *cobra.Command {
checkError(err)
rolloutClient, err := clientset.NewForConfig(config)
checkError(err)
dynamicClient, err := dynamic.NewForConfig(config)
checkError(err)
resyncDuration := time.Duration(rolloutResyncPeriod) * time.Second
kubeInformerFactory := kubeinformers.NewSharedInformerFactoryWithOptions(
kubeClient,
Expand All @@ -91,7 +97,7 @@ func newCommand() *cobra.Command {
kubeinformers.WithTweakListOptions(func(options *metav1.ListOptions) {
options.LabelSelector = jobprovider.AnalysisRunUIDLabelKey
}))
cm := controller.NewManager(kubeClient, rolloutClient,
cm := controller.NewManager(kubeClient, rolloutClient, dynamicClient,
kubeInformerFactory.Apps().V1().ReplicaSets(),
kubeInformerFactory.Core().V1().Services(),
jobInformerFactory.Batch().V1().Jobs(),
Expand All @@ -101,7 +107,8 @@ func newCommand() *cobra.Command {
argoRolloutsInformerFactory.Argoproj().V1alpha1().AnalysisTemplates(),
resyncDuration,
instanceID,
metricsPort)
metricsPort,
defaultIstioVersion)

// notice that there is no need to run Start methods in a separate goroutine. (i.e. go kubeInformerFactory.Start(stopCh)
// Start method is non-blocking and runs all registered informers in a dedicated goroutine.
Expand All @@ -125,6 +132,7 @@ func newCommand() *cobra.Command {
command.Flags().IntVar(&experimentThreads, "experiment-threads", controller.DefaultExperimentThreads, "Set the number of worker threads for the Experiment controller")
command.Flags().IntVar(&analysisThreads, "analysis-threads", controller.DefaultAnalysisThreads, "Set the number of worker threads for the Experiment controller")
command.Flags().IntVar(&serviceThreads, "service-threads", controller.DefaultServiceThreads, "Set the number of worker threads for the Service controller")
command.Flags().StringVar(&istioVersion, "istio-api-version", defaultIstioVersion, "Set the default Istio apiVersion that controller should look when manipulating VirtualServices.")
return &command
}

Expand Down
7 changes: 6 additions & 1 deletion controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"k8s.io/apimachinery/pkg/util/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/dynamic"
appsinformers "k8s.io/client-go/informers/apps/v1"
batchinformers "k8s.io/client-go/informers/batch/v1"
coreinformers "k8s.io/client-go/informers/core/v1"
Expand Down Expand Up @@ -78,6 +79,7 @@ type Manager struct {
func NewManager(
kubeclientset kubernetes.Interface,
argoprojclientset clientset.Interface,
dynamicclientset dynamic.Interface,
replicaSetInformer appsinformers.ReplicaSetInformer,
servicesInformer coreinformers.ServiceInformer,
jobInformer batchinformers.JobInformer,
Expand All @@ -88,6 +90,7 @@ func NewManager(
resyncPeriod time.Duration,
instanceID string,
metricsPort int,
defaultIstioVersion string,
) *Manager {

utilruntime.Must(rolloutscheme.AddToScheme(scheme.Scheme))
Expand All @@ -112,6 +115,7 @@ func NewManager(
rolloutController := rollout.NewRolloutController(
kubeclientset,
argoprojclientset,
dynamicclientset,
experimentsInformer,
analysisRunInformer,
analysisTemplateInformer,
Expand All @@ -122,7 +126,8 @@ func NewManager(
rolloutWorkqueue,
serviceWorkqueue,
metricsServer,
recorder)
recorder,
defaultIstioVersion)

experimentController := experiments.NewExperimentController(
kubeclientset,
Expand Down
20 changes: 20 additions & 0 deletions manifests/crds/rollout-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,26 @@ spec:
type: integer
type: object
type: array
trafficRouting:
properties:
istio:
properties:
virtualService:
properties:
name:
type: string
routes:
items:
type: string
type: array
required:
- name
- routes
type: object
required:
- virtualService
type: object
type: object
type: object
type: object
template:
Expand Down
20 changes: 20 additions & 0 deletions manifests/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8181,6 +8181,26 @@ spec:
type: integer
type: object
type: array
trafficRouting:
properties:
istio:
properties:
virtualService:
properties:
name:
type: string
routes:
items:
type: string
type: array
required:
- name
- routes
type: object
required:
- virtualService
type: object
type: object
type: object
type: object
template:
Expand Down
20 changes: 20 additions & 0 deletions manifests/namespace-install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8181,6 +8181,26 @@ spec:
type: integer
type: object
type: array
trafficRouting:
properties:
istio:
properties:
virtualService:
properties:
name:
type: string
routes:
items:
type: string
type: array
required:
- name
- routes
type: object
required:
- virtualService
type: object
type: object
type: object
type: object
template:
Expand Down
6 changes: 2 additions & 4 deletions metricproviders/mocks/Provider.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

87 changes: 86 additions & 1 deletion pkg/apis/rollouts/v1alpha1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions pkg/apis/rollouts/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ type CanaryStrategy struct {
// Steps define the order of phases to execute the canary deployment
// +optional
Steps []CanaryStep `json:"steps,omitempty"`
// TrafficRouting hosts all the supported service meshes supported to enable more fine-grained traffic routing
TrafficRouting *RolloutTrafficRouting `json:"trafficRouting,omitempty"`

// MaxUnavailable The maximum number of pods that can be unavailable during the update.
// Value can be an absolute number (ex: 5) or a percentage of total pods at the start of update (ex: 10%).
// Absolute number is calculated from percentage by rounding down.
Expand Down Expand Up @@ -153,6 +156,26 @@ type CanaryStrategy struct {
Analysis *RolloutAnalysisStep `json:"analysis,omitempty"`
}

// RolloutTrafficRouting hosts all the different configuration for supported service meshes to enable more fine-grained traffic routing
type RolloutTrafficRouting struct {
// Istio holds Istio specific configuration to route traffic
Istio *IstioTrafficRouting `json:"istio,omitempty"`
}

// IstioTrafficRouting configuration for Istio service mesh to enable fine grain configuration
type IstioTrafficRouting struct {
// VirtualService reference to a Virtual Service that modified to shape traffic
VirtualService IstioVirtualService `json:"virtualService"`
}

// IstioVirtualService holds information on the virtual service the rollout needs to modify
type IstioVirtualService struct {
// Name holds the name of the VirtualService
Name string `json:"name"`
// Routes list of routes within VirtualService to edit
Routes []string `json:"routes"`
}

// RolloutExperimentStep defines a template that is used to create a experiment for a step
type RolloutExperimentStep struct {
// Templates what templates that should be added to the experiment. Should be non-nil
Expand Down
Loading