Skip to content
This repository is currently being migrated. It's locked while the migration is in progress.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions e2e/tests/stable/portal/03-apply-licence.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- command: ../../../../hack/apply-licence.sh
- command: sleep 10
- command: ../../../../hack/grep-iot-logs.sh '\"configurable\":true,\"success\":true},\"licence\":{\"expireDate\":\".*\",\"licenceType\":\"personal\"'
13 changes: 13 additions & 0 deletions hack/apply-licence.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash -ex

: ${URL?= required}
: ${CLIENT_ID?= required}
: ${PASSWORD?= required}

PORTAL_URL=$(echo ${URL} | sed 's/portal-setup/portal-ui/')
LOGIN=$(curl -sX POST ${PORTAL_URL}/graphql -H 'Content-Type: application/json; charset=utf-8' \
-d '{"query": "mutation{authServiceAccount(clientId:\"'${CLIENT_ID}'\",secret:\"'${PASSWORD}'\"){accessToken expires expiresIn}}","variables": {}}')
ACCESS_TOKEN=$(echo ${LOGIN} | grep -e '{"accessToken":"[a-zA-Z0-9._-]\+' | cut -d'"' -f8)
CLUSTER_ID=$(kubectl logs -n storageos -l app.kubernetes.io/component=control-plane -c storageos --tail=-1 | grep "joining cluster" | awk '{print $3}' | cut -d'"' -f1)
curl -sX POST ${PORTAL_URL}/graphql -H 'content-type: application/json' -H "Authorization: Bearer ${ACCESS_TOKEN}" \
--data-raw '{"query":"mutation GenerateLicence($clusterId: String!, $billingLevel: BillingLevel!) {\n generateLicence(clusterId: $clusterId, billingLevel: $billingLevel) {\n status\n payload {\n licence\n __typename\n }\n errors {\n ... on ErrorPayload {\n message\n __typename\n }\n __typename\n }\n __typename\n }\n}","operationName":"GenerateLicence","variables":{"clusterId":"'$CLUSTER_ID'","billingLevel":"free"}}'
2 changes: 1 addition & 1 deletion hack/grep-iot-logs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

echo "Grepping $1"

kubectl logs -n storageos -l app.kubernetes.io/component=portal-manager -c manager --tail -1 | grep publisher.iot | grep "$1"
kubectl logs -n storageos -l app.kubernetes.io/component=portal-manager -c manager --tail -1 | grep publisher.iot | grep -e "$1"
8 changes: 3 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,11 @@ func init() {
func main() {
ctx, cancel := context.WithCancel(ctrl.SetupSignalHandler())
defer func() {
if r := recover(); r != nil {
cancel()
cancel()

time.Sleep(shutDownperiod)
time.Sleep(shutDownperiod)

os.Exit(1)
}
os.Exit(1)
}()

var err error
Expand Down
1 change: 1 addition & 0 deletions pkg/action/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func (as *ActionService) Do(rawAction []byte, updateState func(interface{}) erro
if err := updateState(&state); err != nil {
as.logger.Error(err, "unable to send action state", "actionError", state.Meta.Message)
}
as.logger.V(3).Info("State updated")
}()

action := Action{}
Expand Down
4 changes: 3 additions & 1 deletion pkg/action/licence/licence.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,15 @@ func (h *LicenceActionHandler) Do(payload action.ActionPayload, actionState *sta
return errors.Wrap(err, "unable decode licence")
}

h.logger.V(3).Info("Updating license")
h.logger.V(3).Info("Updating licence")

currentLicence, err := h.storageOSEndpoint.UpdateLicence(string(licence))
if err != nil {
return errors.Wrap(err, "unable update licence")
}

h.logger.V(3).Info("Licence updated")

actionState.Licence = &state.Licence{
ExpireDate: currentLicence.ExpiresAt,
LicenceType: currentLicence.Kind,
Expand Down