Skip to content
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

add: june2024-mid #2

Merged
merged 1 commit into from
Jul 24, 2024
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
17 changes: 13 additions & 4 deletions common/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Configuration struct {
ProdDgraphToken string `json:"prodDgraphToken,omitempty" yaml:"prodDgraphToken,omitempty"`
ExpDgraphToken string `json:"expDgraphToken,omitempty" yaml:"expDgraphToken,omitempty"`
UpgradeToVersion string `json:"upgradeToVersion,omitempty" yaml:"upgradeToVersion,omitempty"`
UpgradeFromVersion string `json:"upgradeFromVersion,omitempty" yaml:"upgradeFromVersion,omitempty"`
RemoteDgraphRestoreUrl string `json:"remoteDgraphRestoreUrl,omitempty" yaml:"remoteDgraphRestoreUrl,omitempty"`
}

Expand All @@ -25,9 +26,10 @@ const (
)

var (
Conf *Configuration
TokenVerifier *ssdjwtauth.Verifier
UpgradeToVersion SchemaOrder
Conf *Configuration
TokenVerifier *ssdjwtauth.Verifier
UpgradeToVersion SchemaOrder
UpgradeFromVersion SchemaOrder
)

func readFilePath(path string) ([]byte, error) {
Expand Down Expand Up @@ -80,7 +82,14 @@ func LoadConfigurationFile(confPath string) {
var ok bool
UpgradeToVersion, ok = schemaOrderMap[Conf.UpgradeToVersion]
if !ok {
logger.Logger.Sugar().Fatalw("unrecognized schema version provided. Please provide in format MonthYYYY eg November2024")
logger.Logger.Sugar().Fatalw("unrecognized schema upgradeTo version provided. Please provide in format MonthYYYY eg November2024")
}

if Conf.UpgradeFromVersion != "" {
UpgradeFromVersion, ok = schemaOrderMap[Conf.UpgradeFromVersion]
if !ok {
logger.Logger.Sugar().Fatalw("unrecognized schema upgradeFrom version provided. Please provide in format MonthYYYY eg November2024")
}
}

}
7 changes: 5 additions & 2 deletions common/schemaHelpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,19 @@ const (
UnIdentifiedVersion SchemaOrder = iota
April2024Version
June2024Version
June2024Version2
)

var SchemasString = map[SchemaOrder]string{
April2024Version: schemas.April2024Schema,
June2024Version: schemas.June2024Schema,
June2024Version2: schemas.June2024Version2,
}

var schemaOrderMap = map[string]SchemaOrder{
"April2024": April2024Version,
"June2024": June2024Version,
"April2024": April2024Version,
"June2024": June2024Version,
"June2024V2": June2024Version2,
}

func (e SchemaOrder) NameOfSchema() string {
Expand Down
15 changes: 15 additions & 0 deletions common/upgradeSteps.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package common
import (
"context"
"fmt"
"strings"

"upgradationScript/april2024june2024"
featuretable "upgradationScript/featureTable"
graphqlfunc "upgradationScript/graphqlFunc"
"upgradationScript/june2024june2024v2"

"upgradationScript/logger"
policyingenstionscript "upgradationScript/policies"
Expand All @@ -29,6 +31,15 @@ func StartUpgrade() error {

logger.Sl.Infof("Current Schema: %s", schemaVersion.NameOfSchema())

if schemaVersion == UnIdentifiedVersion && strings.TrimSpace(Conf.UpgradeFromVersion) == "" {
return fmt.Errorf("schema version not identified")
}

if schemaVersion == UnIdentifiedVersion && Conf.UpgradeFromVersion != "" {
logger.Logger.Info("---------------Could'nt Identify Schema version using the provided config------------------")
schemaVersion = UpgradeFromVersion
}

if checkIfSchemaUpgradeNotPossible(schemaVersion) {
return fmt.Errorf("cannot downgrade schema version. The current schema is at higher version than asked for")
}
Expand Down Expand Up @@ -68,6 +79,10 @@ func beginProcessOfUpgrade(upgradeTo SchemaOrder) error {
expGraphqlClient := graphqlfunc.NewClient(Conf.ExpGraphQLAddr, Conf.ExpDgraphToken)

return april2024june2024.UpgradeToJune2024(Conf.ProdGraphQLAddr, Conf.ProdDgraphToken, Conf.ExpGraphQLAddr, Conf.RemoteDgraphRestoreUrl, prodGraphqlClient, expGraphqlClient)

case June2024Version2:
return june2024june2024v2.UpgradeToJune2024V2(Conf.ProdGraphQLAddr, Conf.ProdDgraphToken, prodGraphqlClient)

}

logger.Sl.Debugf("no upgrade steps for %s", upgradeTo.NameOfSchema())
Expand Down
9 changes: 8 additions & 1 deletion configs/upgrade-job-manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ spec:
job-name: upgrade-job
spec:
containers:
- image: genos1998/upgrade-script:v0.0.15
- image: genos1998/upgrade-script:v0.0.30
imagePullPolicy: IfNotPresent
name: upgrade-job
env:
Expand All @@ -31,8 +31,15 @@ spec:
subPath: upgrade-job.yaml
- name: scanresult
mountPath: /app/scanResult
- name: token
readOnly: true
mountPath: /app/secrets/prod-token/
restartPolicy: Never
volumes:
- name: token
secret:
secretName: ssd-opa-token
defaultMode: 420
- name: datadir
persistentVolumeClaim:
claimName: datadir-dgraph-0
Expand Down
3 changes: 1 addition & 2 deletions configs/upgrade-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ metadata:
data:
upgrade-job.yaml: |
prodGraphQLAddr: https://ssd-jul10-graphql.aoa.oes.opsmx.org
prodDgraphToken: eyJhbGciOiJSUzI1NiIsImtpZCI6IjZiNjRiNTFmLWMyNGItNDRlZS04YTM3LTEzNTkyYWM4MGI3OCIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJPcHNNeCIsImF1ZCI6WyJzc2Qub3BzbXguaW8iXSwiZXhwIjoxNzIxMDUwNDgyLCJuYmYiOjE3MjEwMjg4ODIsImp0aSI6ImIzNjQ3YTY3LTQyN2MtMTFlZi04YWQxLWZlMTU2YmUxNmU4ZSIsInNzZC5vcHNteC5pbyI6eyJ0eXBlIjoiaW50ZXJuYWwtYWNjb3VudC92MSIsImF1dGhvcml6YXRpb25zIjpbImFjY2Vzcy1kZ3JhcGgiXSwic2VydmljZSI6InNzZC1vcGEifX0.AeZdwK8jagDwSyo-H51-zEsPZMvRXS-zyg6T1Ue5MfHI6464po17l4gmz3AwY76rkYHzKH5hXWXbcunhViy6cqf_AmiV4lvNNJmFLfxfSeP7Y0Aa2Qa_6j5NzkhnPVmAsGrek5jhr7TRE3jlh5BO8uC-HJORTwQiCrlycTWTprKBicSp00--QaX3y-xyxJmTC0JTbpW4fDUdT9QgK8w4al0DXEXslnEliBOz5qW1Xmm2WjNgEuwdjQRLctt6cr7tgkdilYqgN0r9QqIYAkn_Y-JtNlqyTYNEFWA_IUXc5IJrVwgPY6lU5eRmZb5jtTeOpjtftqYIB_JULgp3q33Otw
upgradeFromVersion: April2024
upgradeToVersion: June2024
remoteDgraphRestoreUrl: https://ssd-jul10-dbkp.aoa.oes.opsmx.org
expGraphQLAddr: http://dgraph-public:8080
expDgraphToken: eyJhbGciOiJSUzI1NiIsImtpZCI6ImNjOTFlYTBkLWJlYmQtNDM2NC04ODhjLThjZTM0ZWUxYTRmNCIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJPcHNNeCIsImF1ZCI6WyJzc2Qub3BzbXguaW8iXSwiZXhwIjoxNzIxMDUwNDU4LCJuYmYiOjE3MjEwMjg4NTgsImp0aSI6ImE0ZWRiOWJmLTQyN2MtMTFlZi04ZTA4LWYyNjg1MDE0NDBjZiIsInNzZC5vcHNteC5pbyI6eyJ0eXBlIjoiaW50ZXJuYWwtYWNjb3VudC92MSIsImF1dGhvcml6YXRpb25zIjpbImFjY2Vzcy1kZ3JhcGgiXSwic2VydmljZSI6InNzZC1vcGEifX0.eCRWHTwhC961El_1EBZ4lGVGbodLiU9vC-jOz9bpUAMvxrbvTye9nEoSYDZCxwixD_FKbvjfQyE_61xL9o_8FOAT5ywHx3n_NV6THGifiokl8XYp6m3fz--ShwknKi_OpmeJS0rmbpWsq7jhqNTRMJ87WKTnwhCGN10M8DmBoNeaih6W-N9Y98IQPKqPpDxQIAWz2jilnLs3JFVjZ9Z4abC3Dc8RsZaUX7rU2ljTtDyiYvZq81fVez2m0uEo9mfDYX1WRZHcjA6w5k4F62Qq00pCmz9nRTINKwkjJWNrlp1rOqKGIznRw6bFJGN99i8u9B1qT9pCS0HguR1DwABHHg


23 changes: 23 additions & 0 deletions june2024june2024v2/upgradeSteps.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package june2024june2024v2

import (
"fmt"
graphqlfunc "upgradationScript/graphqlFunc"
"upgradationScript/logger"
"upgradationScript/schemas"

"github.com/Khan/genqlient/graphql"
)

func UpgradeToJune2024V2(prodGraphUrl, prodToken string, prodDgraphClient graphql.Client) error {

logger.Logger.Info("--------------Starting UpgradeToJune2024V2------------------")

if err := graphqlfunc.UpdateSchema(prodGraphUrl, prodToken, []byte(schemas.June2024Version2)); err != nil {
return fmt.Errorf("UpgradeToJune2024: UpdateSchema: %s", err.Error())
}

logger.Logger.Info("--------------Completed UpgradeToJune2024V2------------------")

return nil
}
Loading