Skip to content

Commit

Permalink
Support ExtraTagInfo, ExtraFieldInfo, and data verification
Browse files Browse the repository at this point in the history
longhorn/longhorn#5235
https://github.com/longhorn/upgrade-responder/issues/47

Signed-off-by: Phan Le <phan.le@suse.com>
Signed-off-by: Chin-Ya Huang <chin-ya.huang@suse.com>
  • Loading branch information
c3y1huang authored and David Ko committed Jun 27, 2023
1 parent b8ff5f0 commit a0c69c9
Show file tree
Hide file tree
Showing 9 changed files with 444 additions and 60 deletions.
7 changes: 4 additions & 3 deletions chart/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ Create chart name and version as used by the chart label.
{{- end -}}

{{/*
Create configMap name used to store the information about latest version of the application.
Create configMap name used to store the information for the upgrade responder server.
*/}}
{{- define "upgradeResponder.configMapName" -}}
{{- define "upgradeResponder.upgradeResponderConfigMapName" -}}
{{- $fullName := include "upgradeResponder.fullname" . -}}
{{- printf "%s-%s" "configmap" $fullName | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- printf "%s-%s" "upgrade-responder-configmap" $fullName | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}




19 changes: 12 additions & 7 deletions chart/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ spec:
template:
metadata:
annotations:
checksum/responseConfigMap: {{ include (print $.Template.BasePath "/responseConfigMap.yaml") . | sha256sum }}
checksum/upgradeResponderConfigMap: {{ include (print $.Template.BasePath "/upgradeResponderConfigMap.yaml") . | sha256sum }}
labels:
app.kubernetes.io/name: {{ include "upgradeResponder.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
Expand Down Expand Up @@ -57,7 +57,9 @@ spec:
- --application-name
- $(APPLICATION_NAME)
- --upgrade-response-config
- /run/secrets/upgrade-responder-config.json
- /run/secrets/response-config.json
- --request-schema
- /run/secrets/request-schema.json
- --influxdb-url
- $(INFLUXDB_URL)
- --influxdb-user
Expand All @@ -83,9 +85,12 @@ spec:
# path: /
# port: http
volumeMounts:
- mountPath: /run/secrets/upgrade-responder-config.json
name: {{ include "upgradeResponder.configMapName" . }}
subPath: upgrade-responder-config.json
- mountPath: /run/secrets/response-config.json
name: {{ include "upgradeResponder.upgradeResponderConfigMapName" . }}
subPath: response-config.json
- mountPath: /run/secrets/request-schema.json
name: {{ include "upgradeResponder.upgradeResponderConfigMapName" . }}
subPath: request-schema.json
resources:
{{ toYaml .Values.resources | indent 12 }}
{{- with .Values.nodeSelector }}
Expand All @@ -101,6 +106,6 @@ spec:
{{ toYaml . | indent 8 }}
{{- end }}
volumes:
- name: {{ include "upgradeResponder.configMapName" . }}
- name: {{ include "upgradeResponder.upgradeResponderConfigMapName" . }}
configMap:
name: {{ include "upgradeResponder.configMapName" . }}
name: {{ include "upgradeResponder.upgradeResponderConfigMapName" . }}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "upgradeResponder.configMapName" . }}
name: {{ include "upgradeResponder.upgradeResponderConfigMapName" . }}
labels:
"app.kubernetes.io/name": '{{ template "upgradeResponder.name" .}}'
"helm.sh/chart": "{{ .Chart.Name }}-{{ .Chart.Version }}"
"app.kubernetes.io/managed-by": "{{ .Release.Service }}"
"app.kubernetes.io/instance": "{{ .Release.Name }}"
data:
upgrade-responder-config.json: {{ .Values.configMap.responseConfig | toYaml | indent 2 }}
response-config.json: {{ .Values.configMap.responseConfig | toYaml | indent 2 }}
request-schema.json: {{ .Values.configMap.requestSchema | toYaml | indent 2 }}
17 changes: 12 additions & 5 deletions chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,18 @@ secret:
configMap:
responseConfig: |-
{
"Versions": [{
"Name": "v1.0.0",
"ReleaseDate": "2020-05-18T12:30:00Z",
"Tags": ["latest"]
}]
"versions": [{
"name": "v1.0.0",
"releaseDate": "2020-05-18T12:30:00Z",
"tags": ["latest"]
}]
}
requestSchema: |-
{
"appVersionSchema": {
"dataType": "string",
"maxLen": 200
}
}
replicaCount: 3
Expand Down
17 changes: 12 additions & 5 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,21 @@ type UpgradeRequester interface {
}

type Version struct {
Name string // must be in semantic versioning
ReleaseDate string
Tags []string
Name string `json:"name"` // must be in semantic versioning
ReleaseDate string `json:"releaseDate"`
MinUpgradableVersion string `json:"minUpgradableVersion"`
Tags []string `json:"tags"`
ExtraInfo map[string]string `json:"extraInfo"`
}

type CheckUpgradeRequest struct {
AppVersion string `json:"appVersion"`
ExtraInfo map[string]string `json:"extraInfo"`
AppVersion string `json:"appVersion"`

ExtraTagInfo map[string]string `json:"extraTagInfo"`
ExtraFieldInfo map[string]interface{} `json:"extraFieldInfo"`

// Deprecated: replaced by ExtraTagInfo
ExtraInfo map[string]string `json:"extraInfo"`
}

type CheckUpgradeResponse struct {
Expand Down
21 changes: 17 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ var VERSION = "v0.0.0-dev"
const (
FlagUpgradeResponseConfiguration = "upgrade-response-config"
EnvUpgradeResponseConfiguration = "UPGRADE_RESPONSE_CONFIG"
FlagRequestSchema = "request-schema"
EnvRequestSchema = "REQUEST_SCHEMA"
FlagApplicationName = "application-name"
EnvApplicationName = "APPLICATION_NAME"
FlagInfluxDBURL = "influxdb-url"
Expand Down Expand Up @@ -76,6 +78,11 @@ func UpgradeResponderCmd() cli.Command {
EnvVar: EnvUpgradeResponseConfiguration,
Usage: "Specify the response configuration file for upgrade query",
},
cli.StringFlag{
Name: FlagRequestSchema,
EnvVar: EnvRequestSchema,
Usage: "Specify the request schema file which contains the rules that the upgrade responder server use to validate request data before writing to database",
},
cli.StringFlag{
Name: FlagApplicationName,
EnvVar: EnvApplicationName,
Expand Down Expand Up @@ -137,7 +144,8 @@ func startUpgradeResponder(c *cli.Context) error {
return err
}

cfg := c.String(FlagUpgradeResponseConfiguration)
responseConfigFile := c.String(FlagUpgradeResponseConfiguration)
requestSchemaFile := c.String(FlagRequestSchema)
influxURL := c.String(FlagInfluxDBURL)
influxUser := c.String(FlagInfluxDBUser)
influxPass := c.String(FlagInfluxDBPass)
Expand All @@ -149,7 +157,7 @@ func startUpgradeResponder(c *cli.Context) error {
cacheSize := c.Int(FlagCacheSize)

done := make(chan struct{})
server, err := upgraderesponder.NewServer(done, applicationName, cfg, influxURL, influxUser, influxPass, queryPeriod, geodb, cacheSyncInterval, cacheSize)
server, err := upgraderesponder.NewServer(done, applicationName, responseConfigFile, requestSchemaFile, influxURL, influxUser, influxPass, queryPeriod, geodb, cacheSyncInterval, cacheSize)
if err != nil {
return err
}
Expand Down Expand Up @@ -182,11 +190,16 @@ func RegisterShutdownChannel(done chan struct{}) {
}

func validateCommandLineArguments(c *cli.Context) error {
cfg := c.String(FlagUpgradeResponseConfiguration)
if cfg == "" {
responseConfigFile := c.String(FlagUpgradeResponseConfiguration)
if responseConfigFile == "" {
return fmt.Errorf("no upgrade response configuration file specified")
}

requestSchemaFile := c.String(FlagRequestSchema)
if requestSchemaFile == "" {
return fmt.Errorf("no request schema file specified")
}

applicationName := c.String(FlagApplicationName)
if applicationName == "" {
return fmt.Errorf("no application name specified")
Expand Down

0 comments on commit a0c69c9

Please sign in to comment.