-
Notifications
You must be signed in to change notification settings - Fork 24
/
Makefile
126 lines (103 loc) · 5.41 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
include scripts/.env
UNAME_S := $(shell uname -s)
identity={"identity": {"org_id": "3340851", "type": "System", "auth_type": "cert-auth", "system": {"cn": "1b36b20f-7fa0-4454-a6d2-008294e06378", "cert_type": "system"}, "internal": {"org_id": "3340851", "auth_time": 6300}}}
ifeq ($(UNAME_S),Darwin)
b64_identity=$(shell echo '${identity}' | base64)
else
b64_identity=$(shell echo '${identity}' | base64 -w 0 -)
endif
ros_ocp_msg='{"request_id": "uuid1234", "b64_identity": "test", "metadata": {"org_id": "3340851", "source_id": "111", "cluster_uuid": "222", "cluster_alias": "name222"}, "files": ["http://localhost:8888/ros-ocp-usage.csv"]}'
ros_ocp_msg_24Hrs='{"request_id": "uuid1234", "b64_identity": "test", "metadata": {"org_id": "3340851", "source_id": "111", "cluster_uuid": "222", "cluster_alias": "name222"}, "files": ["http://localhost:8888/ros-ocp-usage-24Hrs.csv"]}'
file=./scripts/samples/cost-mgmt.tar.gz
CSVfile=./scripts/samples/ros-ocp-usage.csv
CSVfile_name_tuple := $(subst /, ,$(CSVfile:%=%))
CSVfile_name := $(word 4,$(CSVfile_name_tuple))
INGRESS_PORT ?= 3000
ifdef env
short_env=$(shell echo '${env}' | cut -d'-' -f2)
server=$(shell oc get clowdenvironments env-ephemeral-${short_env} -o=jsonpath='{.status.hostname}')
username=$(shell oc get secret env-ephemeral-${short_env}-keycloak -n ephemeral-${short_env} -o=jsonpath='{.data.defaultUsername}' | base64 -d)
password=$(shell oc get secret env-ephemeral-${short_env}-keycloak -n ephemeral-${short_env} -o=jsonpath='{.data.defaultPassword}' | base64 -d)
auth_header=$(shell echo -n '${username}:${password}' | base64)
minio_accessKey=$(shell oc get secret env-ephemeral-${short_env}-minio -o=jsonpath='{.data.accessKey}' | base64 -d)
minio_secretKey=$(shell oc get secret env-ephemeral-${short_env}-minio -o=jsonpath='{.data.secretKey}' | base64 -d)
endif
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
ifeq (,$(wildcard $(LOCALBIN)))
@echo "🤖 Ensuring $(LOCALBIN) is available"
mkdir -p $(LOCALBIN)
@echo "✅ Done"
endif
.PHONY: golangci-lint
GOLANGCILINT := $(LOCALBIN)/golangci-lint
GOLANGCI_URL := https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh
start_date := 1970-01-01
golangci-lint: $(LOCALBIN)
ifeq (,$(wildcard $(GOLANGCILINT)))
@ echo "📥 Downloading golangci-lint"
curl -sSfL $(GOLANGCI_URL) | sh -s -- -b $(LOCALBIN) $(GOLANGCI_VERSION)
@ echo "✅ Done"
endif
.PHONY: install-golang-migrate-cli-tool
install-golang-migrate-cli-tool: $(LOCALBIN)
curl -L https://github.com/golang-migrate/migrate/releases/download/v4.15.2/migrate.linux-amd64.tar.gz | tar xvz -C $(LOCALBIN) migrate
.PHONY: db-migrate
db-migrate:
go run rosocp.go db migrate up
.PHONY: run-processor
run-processor:
PROMETHEUS_PORT=5005 go run rosocp.go start processor
.PHONY: run-recommender
run-recommendation-poller:
PROMETHEUS_PORT=5006 go run rosocp.go start recommendation-poller
.PHONY: run-api-server
run-api-server:
PROMETHEUS_PORT=5007 go run rosocp.go start api
.PHONY: build
build:
go build -o bin/rosocp rosocp.go
.PHONY: lint
lint: golangci-lint
$(GOLANGCILINT) run --timeout=3m ./...
.PHONY: test
test:
go test -v ./...
MCCILINT := $(LOCALBIN)/mc
.PHONY: archive-to-minio
archive-to-minio:
ifdef env
-oc expose svc env-${env}-minio -n ${env}
ifeq (,$(wildcard $(MCCILINT)))
@ echo "📥 Downloading minio client"
ifeq ($(UNAME_S),Darwin)
curl https://dl.min.io/client/mc/release/darwin-amd64/mc --create-dirs -o $(MCCILINT)
else
curl https://dl.min.io/client/mc/release/linux-amd64/mc --create-dirs -o $(MCCILINT)
endif
chmod +x $(MCCILINT)
@ echo "✅ Done"
endif
bin/mc alias set myminio http://env-${env}-minio-${env}.apps.crc-eph.r9lp.p1.openshiftapps.com ${minio_accessKey} ${minio_secretKey}
bin/mc cp ${CSVfile} myminio/insights-upload-perma/
sleep 5
$(eval SHAREURL=$(shell bin/mc share download --json myminio/insights-upload-perma/${CSVfile_name} | jq -r '.share'))
$(eval KAFKAPOD=$(shell oc get pods -o custom-columns=POD:.metadata.name --no-headers -n ${env} | grep kafka))
$(eval ros_ocp_msg_ephemeral = '{\"request_id\": \"uuid1234\", \"b64_identity\": \"test\", \"metadata\": {\"org_id\": \"3340851\", \"source_id\": \"111\", \"cluster_uuid\": \"222\", \"cluster_alias\": \"name222\"}, \"files\": [\"$(SHAREURL)\"]}')
oc exec ${KAFKAPOD} -n ${env} -- /bin/bash -c "echo ${ros_ocp_msg_ephemeral} | /opt/kafka/bin/kafka-console-producer.sh --topic hccm.ros.events --broker-list localhost:9092"
else
@ echo "Env not defined"
endif
upload-msg-to-rosocp:
echo ${ros_ocp_msg} | docker-compose -f scripts/docker-compose.yml exec -T kafka kafka-console-producer --topic hccm.ros.events --broker-list localhost:29092
upload-msg-to-rosocp-24Hrs:
echo ${ros_ocp_msg_24Hrs} | docker-compose -f scripts/docker-compose.yml exec -T kafka kafka-console-producer --topic hccm.ros.events --broker-list localhost:29092
get-recommendations:
ifdef env
$(eval APIPOD=$(shell oc get pods -o custom-columns=POD:.metadata.name --no-headers -n ${env} | grep ros-ocp-backend-api))
oc exec ${APIPOD} -c ros-ocp-backend-api -n ${env} -- /bin/bash -c 'curl -v -H "X-Rh-Identity: ${b64_identity}" -H "x-rh-request_id: testtesttest" http://localhost:8000/api/cost-management/v1/recommendations/openshift?start_date=${start_date}' | python -m json.tool
else
curl -v -H "x-rh-identity: ${b64_identity}" \
-H "x-rh-request_id: testtesttest" \
http://localhost:8000/api/cost-management/v1/recommendations/openshift?start_date=${start_date} | python -m json.tool
endif