-
Notifications
You must be signed in to change notification settings - Fork 707
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
1521 delete tables on upgrade #1532
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# Invalidate the chart cache during upgrade. | ||
apiVersion: batch/v1 | ||
kind: Job | ||
metadata: | ||
name: {{ template "kubeapps.apprepository-jobs-preupgrade.fullname" . }} | ||
annotations: | ||
helm.sh/hook: pre-upgrade | ||
helm.sh/hook-delete-policy: hook-succeeded | ||
labels: | ||
app: {{ template "kubeapps.apprepository-jobs-preupgrade.fullname" . }} | ||
chart: {{ template "kubeapps.chart" . }} | ||
release: {{ .Release.Name }} | ||
heritage: {{ .Release.Service }} | ||
spec: | ||
template: | ||
metadata: | ||
labels: | ||
app: {{ template "kubeapps.apprepository-jobs-preupgrade.fullname" . }} | ||
release: {{ .Release.Name }} | ||
spec: | ||
{{- include "kubeapps.imagePullSecrets" . | indent 6 }} | ||
{{- if .Values.hooks.affinity }} | ||
affinity: {{- include "kubeapps.tplValue" (dict "value" .Values.hooks.affinity "context" $) | nindent 8 }} | ||
{{- end }} | ||
{{- if .Values.hooks.nodeSelector }} | ||
nodeSelector: {{- include "kubeapps.tplValue" (dict "value" .Values.hooks.nodeSelector "context" $) | nindent 8 }} | ||
{{- end }} | ||
{{- if .Values.hooks.tolerations }} | ||
tolerations: {{- include "kubeapps.tplValue" (dict "value" .Values.hooks.tolerations "context" $) | nindent 8 }} | ||
{{- end }} | ||
{{- if .Values.securityContext.enabled }} | ||
securityContext: | ||
fsGroup: {{ .Values.securityContext.fsGroup }} | ||
runAsUser: {{ .Values.securityContext.runAsUser }} | ||
{{- end }} | ||
restartPolicy: OnFailure | ||
containers: | ||
- name: invalidate-cache | ||
image: {{ template "kubeapps.image" (list .Values.apprepository.syncImage .Values.global) }} | ||
command: | ||
- /asset-syncer | ||
args: | ||
- invalidate-cache | ||
{{- if .Values.mongodb.enabled }} | ||
- --database-type=mongodb | ||
- --database-url={{ template "kubeapps.mongodb.fullname" . }} | ||
- --database-user=root | ||
- --database-name=charts | ||
{{- end }} | ||
{{- if .Values.postgresql.enabled }} | ||
- --database-type=postgresql | ||
- --database-url={{ template "kubeapps.postgresql.fullname" . }}:5432 | ||
- --database-user=postgres | ||
- --database-name=assets | ||
{{- end }} | ||
env: | ||
- name: DB_PASSWORD | ||
valueFrom: | ||
secretKeyRef: | ||
{{- if .Values.mongodb.enabled }} | ||
key: mongodb-root-password | ||
name: {{ .Values.mongodb.existingSecret }} | ||
{{- end }} | ||
{{- if .Values.postgresql.enabled }} | ||
key: postgresql-password | ||
name: {{ .Values.postgresql.existingSecret }} | ||
{{- end }} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
Copyright (c) 2020 Bitnami | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"github.com/kubeapps/common/datastore" | ||
"github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var invalidateCacheCmd = &cobra.Command{ | ||
Use: "invalidate-cache", | ||
Short: "removes all data so the cache can be rebuilt", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if len(args) != 0 { | ||
logrus.Info("This command does not take any arguments") | ||
cmd.Help() | ||
return | ||
} | ||
|
||
if debug { | ||
logrus.SetLevel(logrus.DebugLevel) | ||
} | ||
|
||
dbConfig := datastore.Config{URL: databaseURL, Database: databaseName, Username: databaseUser, Password: databasePassword} | ||
manager, err := newManager(databaseType, dbConfig) | ||
if err != nil { | ||
logrus.Fatal(err) | ||
} | ||
err = manager.Init() | ||
if err != nil { | ||
logrus.Fatal(err) | ||
} | ||
defer manager.Close() | ||
|
||
err = manager.InvalidateCache() | ||
if err != nil { | ||
logrus.Fatal(err) | ||
} | ||
logrus.Infof("Successfully invalidated cache") | ||
}, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -247,3 +247,14 @@ func (m *postgresAssetManager) insertFiles(chartFilesID string, files models.Cha | |
} | ||
return err | ||
} | ||
|
||
// InvalidateCache for postgresql deletes and re-writes the schema | ||
func (m *postgresAssetManager) InvalidateCache() error { | ||
tables := strings.Join([]string{dbutils.RepositoryTable, dbutils.ChartTable, dbutils.ChartFilesTable}, ",") | ||
_, err := m.DB.Exec(fmt.Sprintf("DROP TABLE IF EXISTS %s CASCADE", tables)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not here it's not, thanks. I'd originally only deleted the one table and relied on the cascades, but I had to change that as the files table doesn't have a FK in this PR. I've removed the CASCADE and will re-add it when the FK's are in the next PR (I think)> |
||
if err != nil { | ||
return err | ||
} | ||
|
||
return m.initTables() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is not really necessary since it will be executed with syncing but I am okay if you want to leave it to leave the tables ready There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, the reason for having it here is so that it is sync'd with the correct code (the new, rather than from the still running older pods). We will probably need a transaction here to avoid race conditions with the existing pods too. |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm assuming this is an old job which no longer exists, as I couldn't see the name being used anywhere.