Skip to content

Commit

Permalink
fix: resolve conflicts
Browse files Browse the repository at this point in the history
Signed-off-by: Philipp Plotnikov <[email protected]>
  • Loading branch information
Philipp-Plotnikov committed Feb 17, 2024
2 parents 0cada4c + 59f8145 commit e17a159
Show file tree
Hide file tree
Showing 17 changed files with 847 additions and 213 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
branches:
- "main"
env:
GOLANG_VERSION: '1.19'
GOLANG_VERSION: '1.20'

jobs:
unit-tests:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- "release-v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+"

env:
GOLANG_VERSION: "1.19"
GOLANG_VERSION: "1.20"

jobs:
release-creation:
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ data:
Deploy this file with `kubectl` or Argo CD or any other deployment method you use for your cluster.

Restart the Argo Rollouts pod for the plug-in to take effect.
```shell
kubectl rollout restart deployment -n argo-rollouts argo-rollouts
```

For more details see the [Plugin documentation](https://argoproj.github.io/argo-rollouts/features/traffic-management/plugins/) at Argo Rollouts.

## Feedback needed
Expand Down
14 changes: 10 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.18.0 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/hashicorp/go-hclog v1.5.0 // indirect
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
Expand All @@ -29,8 +34,9 @@ require (
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/crypto v0.19.0 // indirect
golang.org/x/oauth2 v0.11.0 // indirect
golang.org/x/term v0.11.0 // indirect
golang.org/x/term v0.17.0 // indirect
golang.org/x/time v0.3.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230815205213-6bfd019c3878 // indirect
Expand All @@ -52,9 +58,9 @@ require (
github.com/mailru/easyjson v0.7.7 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/text v0.12.0 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
20 changes: 20 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ github.com/evanphx/json-patch v5.6.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLi
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ=
github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
Expand All @@ -22,6 +24,12 @@ github.com/go-openapi/jsonreference v0.20.2/go.mod h1:Bl1zwGIM8/wsvqjsOQLJ/SH+En
github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
github.com/go-openapi/swag v0.22.4 h1:QLMzNJnMGPRNDCbySlcj1x01tzU8/9LTTL9hZZZogBU=
github.com/go-openapi/swag v0.22.4/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.18.0 h1:BvolUXjp4zuvkZ5YN5t7ebzbhlUtPsPm2S9NAZ5nl9U=
github.com/go-playground/validator/v10 v10.18.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
Expand Down Expand Up @@ -61,6 +69,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
Expand Down Expand Up @@ -111,6 +121,8 @@ github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9dec
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo=
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
Expand All @@ -120,6 +132,8 @@ golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14=
golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/oauth2 v0.11.0 h1:vPL4xzxBM4niKCW6g9whtaWVXTJf1U5e4aZxxFx/gbU=
golang.org/x/oauth2 v0.11.0/go.mod h1:LdF7O/8bLR/qWK9DrpXmbHLTouvRHK0SgJl0GmDBchk=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand All @@ -138,13 +152,19 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.11.0 h1:F9tnn/DA/Im8nCwm+fX+1/eBwi4qFjRT++MhtVC4ZX0=
golang.org/x/term v0.11.0/go.mod h1:zC9APTIj3jG3FdV/Ons+XE1riIZXG4aZ4GTHiPZJPIU=
golang.org/x/term v0.17.0 h1:mkTF7LCd6WGJNL3K1Ad7kwxNfYAW6a8a8QqtMblp/4U=
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc=
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4=
golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand Down
3 changes: 3 additions & 0 deletions internal/defaults/defaults.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package defaults

const ConfigMap = "argo-gatewayapi-configmap"
119 changes: 119 additions & 0 deletions internal/utils/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package utils

import (
"encoding/json"
"strings"

pluginTypes "github.com/argoproj/argo-rollouts/utils/plugin/types"
log "github.com/sirupsen/logrus"
v1 "k8s.io/api/core/v1"
kubeErrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
)

func GetKubeConfig() (*rest.Config, error) {
loadingRules := clientcmd.NewDefaultClientConfigLoadingRules()
// if you want to change the loading rules (which files in which order), you can do so here
configOverrides := &clientcmd.ConfigOverrides{}
// if you want to change override values or bind them to flags, there are methods to help you
kubeConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, configOverrides)
config, err := kubeConfig.ClientConfig()
if err != nil {
return nil, pluginTypes.RpcError{ErrorString: err.Error()}
}
return config, nil
}

func SetLogLevel(logLevel string) {
level, err := log.ParseLevel(logLevel)
if err != nil {
log.Fatal(err)
}
log.SetLevel(level)
}

func CreateFormatter(logFormat string) log.Formatter {
var formatType log.Formatter
switch strings.ToLower(logFormat) {
case "json":
formatType = &log.JSONFormatter{}
case "text":
formatType = &log.TextFormatter{
FullTimestamp: true,
}
default:
log.Infof("Unknown format: %s. Using text logformat", logFormat)
formatType = &log.TextFormatter{
FullTimestamp: true,
}
}
return formatType
}

func CreateConfigMap(name string, options CreateConfigMapOptions) (*v1.ConfigMap, error) {
clientset := options.Clientset
ctx := options.Ctx
configMap, err := clientset.Get(ctx, name, metav1.GetOptions{})
if err != nil && !kubeErrors.IsNotFound(err) {
return nil, err
}
if err == nil {
return configMap, err
}
configMap.Name = name
configMap, err = clientset.Create(ctx, configMap, metav1.CreateOptions{})
if err != nil {
return nil, err
}
return configMap, err
}

func GetConfigMapData(configMap *v1.ConfigMap, configMapKey string, destination any) error {
if configMap.Data != nil && configMap.Data[configMapKey] != "" {
err := json.Unmarshal([]byte(configMap.Data[configMapKey]), &destination)
if err != nil {
return err
}
}
return nil
}

func UpdateConfigMapData(configMap *v1.ConfigMap, configMapData any, options UpdateConfigMapOptions) error {
clientset := options.Clientset
rawConfigMapData, err := json.Marshal(configMapData)
if err != nil {
return err
}
if configMap.Data == nil {
configMap.Data = make(map[string]string)
}
configMap.Data[options.ConfigMapKey] = string(rawConfigMapData)
_, err = clientset.Update(options.Ctx, configMap, metav1.UpdateOptions{})
return err
}

func RemoveIndex[T any](original []T, index int) []T {
result := original[:index]
return append(result, original[index+1:]...)
}

func DoTransaction(logCtx *log.Entry, taskList ...Task) error {
var err, reverseErr error
for index, task := range taskList {
err = task.Action()
if err == nil {
continue
}
logCtx.Error(err.Error())
for i := index - 1; i > -1; i-- {
reverseErr = taskList[i].ReverseAction()
if err != nil {
return reverseErr
}
}
return err
}
return nil
}
23 changes: 23 additions & 0 deletions internal/utils/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package utils

import (
"context"

v1 "k8s.io/client-go/kubernetes/typed/core/v1"
)

type CreateConfigMapOptions struct {
Clientset v1.ConfigMapInterface
Ctx context.Context
}

type UpdateConfigMapOptions struct {
Clientset v1.ConfigMapInterface
ConfigMapKey string
Ctx context.Context
}

type Task struct {
Action func() error
ReverseAction func() error
}
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package main

import (
"github.com/argoproj-labs/rollouts-plugin-trafficrouter-gatewayapi/internal/utils"
"github.com/argoproj-labs/rollouts-plugin-trafficrouter-gatewayapi/pkg/plugin"
"github.com/argoproj-labs/rollouts-plugin-trafficrouter-gatewayapi/utils"

rolloutsPlugin "github.com/argoproj/argo-rollouts/rollout/trafficrouting/plugin/rpc"
goPlugin "github.com/hashicorp/go-plugin"
Expand Down
39 changes: 30 additions & 9 deletions pkg/mocks/plugin.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mocks

import (
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"sigs.k8s.io/gateway-api/apis/v1alpha2"
Expand All @@ -9,18 +10,26 @@ import (
)

const (
HTTPRoute = "HTTPRoute"
TCPRoute = "TCPRoute"
StableServiceName = "argo-rollouts-stable-service"
CanaryServiceName = "argo-rollouts-canary-service"
HTTPRouteName = "argo-rollouts-http-route"
TCPRouteName = "argo-rollouts-tcp-route"
Namespace = "default"
HTTPRoute = "HTTPRoute"
TCPRoute = "TCPRoute"
StableServiceName = "argo-rollouts-stable-service"
CanaryServiceName = "argo-rollouts-canary-service"
HTTPRouteName = "argo-rollouts-http-route"
TCPRouteName = "argo-rollouts-tcp-route"
Namespace = "default"
ConfigMapName = "test-config"
HTTPManagedRouteName = "test-http-header-route"
)

var (
port = v1beta1.PortNumber(80)
weight int32 = 0
port = v1beta1.PortNumber(80)
weight int32 = 0
httpPathMatchType = v1beta1.PathMatchPathPrefix
httpPathMatchValue = "/"
httpPathMatch = v1beta1.HTTPPathMatch{
Type: &httpPathMatchType,
Value: &httpPathMatchValue,
}
)

var HTTPRouteObj = v1beta1.HTTPRoute{
Expand Down Expand Up @@ -58,6 +67,11 @@ var HTTPRouteObj = v1beta1.HTTPRoute{
},
},
},
Matches: []v1beta1.HTTPRouteMatch{
{
Path: &httpPathMatch,
},
},
},
},
},
Expand Down Expand Up @@ -98,3 +112,10 @@ var TCPPRouteObj = v1alpha2.TCPRoute{
},
},
}

var ConfigMapObj = v1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: ConfigMapName,
Namespace: Namespace,
},
}
12 changes: 12 additions & 0 deletions pkg/plugin/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package plugin

const (
GatewayAPIUpdateError = "error updating Gateway API %q: %s"
GatewayAPIManifestError = "No routes configured. One of 'tcpRoutes', 'httpRoutes', 'tcpRoute' or 'httpRoute' should be set"
HTTPRouteFieldIsEmptyError = "httpRoute field is empty. It has to be set to remove managed routes"
InvalidHeaderMatchTypeError = "invalid header match type"
BackendRefWasNotFoundInHTTPRouteError = "backendRef was not found in httpRoute"
BackendRefWasNotFoundInTCPRouteError = "backendRef was not found in tcpRoute"
BackendRefListWasNotFoundInTCPRouteError = "backendRef list was not found in tcpRoute"
ManagedRouteMapEntryDeleteError = "can't delete key %q from managedRouteMap. The key %q is not in the managedRouteMap"
)
Loading

0 comments on commit e17a159

Please sign in to comment.