Skip to content

Commit

Permalink
Merge pull request #65 from 3scale/fixes
Browse files Browse the repository at this point in the history
Fixes
  • Loading branch information
unleashed committed Mar 7, 2019
2 parents c79878c + 095ac3e commit d84c4c6
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ To generate these manifests from a deployed adapter, run the following:
```bash
oc exec -n istio-system $(oc get po -n istio-system -o jsonpath='{.items[?(@.metadata.labels.app=="3scale-istio-adapter")].metadata.name}') \
-it -- ./3scale-config-gen \
--url="https:\\replace-me@3scale.net:443" --service="example-service-id" --token="access-token"
--url="https://replace-me.3scale.net:443" --service="example-service-id" --token="access-token"
```

This will produce some sample output to the terminal. As well as a unique UID which must be used for multiple service use case.
Expand All @@ -221,9 +221,9 @@ Edit these samples if required and create the objects using `oc create` command.
Update the workload (target service deployment's Pod Spec) with the required annotations:

```bash
export UID="replace-me"
export SVC_ID="replace-me"
export DEPLOYMENT="replace-me"
patch="$(oc get deployment "${DEPLOYMENT}" --template='{"spec":{"template":{"metadata":{"labels":{ {{ range $k,$v := .spec.template.metadata.labels }}"{{ $k }}":"{{ $v }}",{{ end }}"service-mesh.3scale.net":"true","":"'"${UID}"'"}}}}}' )"
patch="$(oc get deployment "${DEPLOYMENT}" --template='{"spec":{"template":{"metadata":{"labels":{ {{ range $k,$v := .spec.template.metadata.labels }}"{{ $k }}":"{{ $v }}",{{ end }}"service-mesh.3scale.net":"true","service-mesh.3scale.net/uid":"'"${SVC_ID}"'"}}}}}' )"
oc patch deployment "${DEPLOYMENT}" --patch ''"${patch}"''
```

Expand Down
2 changes: 1 addition & 1 deletion cmd/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func execute() error {
return fmt.Errorf("error - generating configuration - %s", err.Error())
}

cg.PopulateDefaultRules()
cg.Rule.Conditions = append(cg.Rule.Conditions, cg.GetDefaultMatchConditions()...)

if outputTo == "" {
writeTo = os.Stdout
Expand Down
6 changes: 3 additions & 3 deletions pkg/templating/manifest_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ metadata:
spec:
adapter: threescale
params:
service_id: "{{.GetUID}}"
service_id: "{{.GetServiceID}}"
system_url: "{{.Handler.SystemURL}}"
access_token: "{{.Handler.AccessToken}}"
connection:
Expand Down Expand Up @@ -201,12 +201,12 @@ func (cg ConfigGenerator) OutputUID(w io.Writer) error {
}

// PopulateDefaultRules is a helper method exposed to allow to generate the rule based on the constructed ConfigGenerator
func (cg ConfigGenerator) PopulateDefaultRules() {
func (cg ConfigGenerator) GetDefaultMatchConditions() []string {
conditions := MatchConditions{
`destination.labels["service-mesh.3scale.net"] == "true"`,
fmt.Sprintf(`destination.labels["service-mesh.3scale.net/uid"] == "%s"`, cg.GetUID()),
}
cg.Rule.Conditions = append(cg.Rule.Conditions, conditions...)
return conditions
}

// GenerateListenString - creates a string from the provided Handler replacing unset/invalid values
Expand Down
4 changes: 2 additions & 2 deletions pkg/templating/manifest_generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,8 @@ func TestOutputUID(t *testing.T) {

func TestPopulateDefaultRules(t *testing.T) {
copy := defaultTestFixture
copy.PopulateDefaultRules()
if len(copy.Rule.Conditions) != 2 {
rules := copy.GetDefaultMatchConditions()
if len(rules) != 2 {
t.Errorf("expected two rules")
}

Expand Down

0 comments on commit d84c4c6

Please sign in to comment.