Skip to content

Commit 6ae176e

Browse files
Merge pull request openshift#214 from jeefy/SDCICD-129
SDCICD-129: Update metadata json file upon every metadata instance change
2 parents b4f9700 + e8be937 commit 6ae176e

File tree

6 files changed

+64
-10
lines changed

6 files changed

+64
-10
lines changed

common/e2e.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func RunE2ETests(t *testing.T) {
5959
t.Fatalf("could not setup OSD: %v", err)
6060
}
6161

62-
metadata.Instance.Environment = cfg.OCM.Env
62+
metadata.Instance.SetEnvironment(cfg.OCM.Env)
6363

6464
// check that enough quota exists for this test if creating cluster
6565
if len(state.Cluster.ID) == 0 {

common/setup.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ func setupCluster() (err error) {
119119
}
120120
}
121121

122-
metadata.Instance.ClusterName = state.Cluster.Name
123-
metadata.Instance.ClusterID = state.Cluster.ID
122+
metadata.Instance.SetClusterName(state.Cluster.Name)
123+
metadata.Instance.SetClusterID(state.Cluster.ID)
124124

125125
if err = OSD.WaitForClusterReady(); err != nil {
126126
return fmt.Errorf("failed waiting for cluster ready: %v", err)

common/version.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ func ChooseVersions(osd *osd.OSD) (err error) {
3030
}
3131

3232
// Set the versions in metadata. If upgrade hasn't been chosen, it should still be omitted from the end result.
33-
metadata.Instance.ClusterVersion = state.Cluster.Name
34-
metadata.Instance.UpgradeVersion = state.Upgrade.ReleaseName
33+
metadata.Instance.SetClusterVersion(state.Cluster.Version)
34+
metadata.Instance.SetUpgradeVersion(state.Upgrade.ReleaseName)
3535

3636
return err
3737
}
@@ -110,7 +110,7 @@ func setupUpgradeVersion(osd *osd.OSD) (err error) {
110110
if cisUpgradeVersion.GreaterThan(clusterVersion) {
111111
log.Printf("Using cluster image set.")
112112
state.Upgrade.ReleaseName = cisUpgradeVersionString
113-
metadata.Instance.UpgradeVersionSource = "cluster image set"
113+
metadata.Instance.SetUpgradeVersionSource("cluster image set")
114114
log.Printf("Selecting version '%s' to be able to upgrade to '%s'", state.Cluster.Version, state.Upgrade.ReleaseName)
115115
return nil
116116
}

pkg/metadata/metadata.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"io/ioutil"
66
"os"
77
"path/filepath"
8+
9+
"github.com/openshift/osde2e/pkg/config"
810
)
911

1012
const (
@@ -40,6 +42,58 @@ func init() {
4042
Instance = &Metadata{}
4143
}
4244

45+
// Next are a bunch of setter functions that allow us
46+
// to track/trap changes to metadata and then flush
47+
// the changes to a file.
48+
49+
// SetClusterID sets the cluster id
50+
func (m *Metadata) SetClusterID(id string) {
51+
m.ClusterID = id
52+
m.WriteToJSON(config.Instance.ReportDir)
53+
}
54+
55+
// SetClusterName sets the cluster name
56+
func (m *Metadata) SetClusterName(name string) {
57+
m.ClusterName = name
58+
m.WriteToJSON(config.Instance.ReportDir)
59+
}
60+
61+
// SetClusterVersion sets the cluster version
62+
func (m *Metadata) SetClusterVersion(version string) {
63+
m.ClusterVersion = version
64+
m.WriteToJSON(config.Instance.ReportDir)
65+
}
66+
67+
// SetEnvironment sets the cluster environment
68+
func (m *Metadata) SetEnvironment(env string) {
69+
m.Environment = env
70+
m.WriteToJSON(config.Instance.ReportDir)
71+
}
72+
73+
// SetUpgradeVersion sets the cluster upgrade version
74+
func (m *Metadata) SetUpgradeVersion(ver string) {
75+
m.UpgradeVersion = ver
76+
m.WriteToJSON(config.Instance.ReportDir)
77+
}
78+
79+
// SetUpgradeVersionSource sets the cluster upgrade version source
80+
func (m *Metadata) SetUpgradeVersionSource(src string) {
81+
m.UpgradeVersionSource = src
82+
m.WriteToJSON(config.Instance.ReportDir)
83+
}
84+
85+
// SetTimeToOCMReportingInstalled sets the time it took for OCM to report a cluster provisioned
86+
func (m *Metadata) SetTimeToOCMReportingInstalled(timeToOCMReportingInstalled float64) {
87+
m.TimeToOCMReportingInstalled = timeToOCMReportingInstalled
88+
m.WriteToJSON(config.Instance.ReportDir)
89+
}
90+
91+
// SetTimeToClusterReady sets the time it took for OCM to report a cluster ready
92+
func (m *Metadata) SetTimeToClusterReady(timeToClusterReady float64) {
93+
m.TimeToClusterReady = timeToClusterReady
94+
m.WriteToJSON(config.Instance.ReportDir)
95+
}
96+
4397
// WriteToJSON will marshall the metadata struct and write it into the given file.
4498
func (m *Metadata) WriteToJSON(reportDir string) (err error) {
4599
var data []byte

pkg/osd/cluster.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,15 +188,15 @@ func (u *OSD) WaitForClusterReady() error {
188188
// This is the first time that we've entered this section, so we'll consider this the time until OCM has said the cluster is ready
189189
if !ocmReady {
190190
ocmReady = true
191-
metadata.Instance.TimeToOCMReportingInstalled = time.Since(clusterStarted).Seconds()
191+
metadata.Instance.SetTimeToOCMReportingInstalled(time.Since(clusterStarted).Seconds())
192192
readinessStarted = time.Now()
193193
}
194194
if success, err := u.PollClusterHealth(); success {
195195
cleanRuns++
196196
log.Printf("Clean run %d/%d...", cleanRuns, cleanRunWindow)
197197
errRuns = 0
198198
if cleanRuns == cleanRunWindow {
199-
metadata.Instance.TimeToClusterReady = time.Since(readinessStarted).Seconds()
199+
metadata.Instance.SetTimeToClusterReady(time.Since(readinessStarted).Seconds())
200200
return true, nil
201201
}
202202
return false, nil

pkg/upgrade/releases.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ func LatestRelease(releaseStream string, useReleaseControllerForInt bool) (name,
4747
return "", "", fmt.Errorf("error decoding body of '%s': %v", data, err)
4848
}
4949

50-
metadata.Instance.UpgradeVersionSource = "release controller"
50+
metadata.Instance.SetUpgradeVersionSource("release controller")
5151

5252
return ensureReleasePrefix(latest.Name), latest.PullSpec, nil
5353
}
5454

5555
log.Printf("Using Cincinnati.")
56-
metadata.Instance.UpgradeVersionSource = "cincinnati"
56+
metadata.Instance.SetUpgradeVersionSource("cincinnati")
5757

5858
// If stage or prod, use Cincinnati instead of the release controller
5959
cincinnatiFormattedURL := fmt.Sprintf(cincinnatiURLFmt, osd.Environments.Choose(env), releaseStream)

0 commit comments

Comments
 (0)