Skip to content

Commit 6e3e23f

Browse files
authored
Add END OF LIFE coloumn to getmesh list (#124)
* Add END OF LIFE coloumn to `getmesh list` Signed-off-by: Arko Dasgupta <[email protected]>
1 parent 33ca8f0 commit 6e3e23f

File tree

4 files changed

+67
-9
lines changed

4 files changed

+67
-9
lines changed

internal/manifest/manifest.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,23 @@ func fetchManifest(url string) (*Manifest, error) {
7272
return nil, fmt.Errorf("error unmarshalling fetched manifest: %v", err)
7373
}
7474

75+
// Populate End of Life field within each distribution
76+
if err := (&ret).SetEOLInIstioDistributions(); err != nil {
77+
return nil, fmt.Errorf("error setting end of life in istio distribution: %v", err)
78+
}
7579
return &ret, nil
7680
}
7781

7882
func PrintManifest(ms *Manifest, current *IstioDistribution) error {
79-
column := []string{"ISTIO VERSION", "FLAVOR", "FLAVOR VERSION", "K8S VERSIONS"}
83+
column := []string{"ISTIO VERSION", "FLAVOR", "FLAVOR VERSION", "K8S VERSIONS", "END OF LIFE"}
8084
data := make([][]string, len(ms.IstioDistributions))
8185
for i, m := range ms.IstioDistributions {
8286
ps := strings.Join(m.K8SVersions, ",")
8387
if current != nil && m.Equal(current) {
8488
m.Version = "*" + m.Version
8589
}
8690
data[i] = []string{m.Version, m.Flavor,
87-
strconv.Itoa(int(m.FlavorVersion)), ps}
91+
strconv.Itoa(int(m.FlavorVersion)), ps, m.EndOfLife}
8892
}
8993

9094
table := tablewriter.NewWriter(logger.GetWriter())

internal/manifest/manifest_test.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,22 +84,24 @@ func TestPrintManifest(t *testing.T) {
8484
Flavor: IstioDistributionFlavorTetrate,
8585
FlavorVersion: 0,
8686
K8SVersions: []string{"1.16"},
87+
EndOfLife: "2022-01-01",
8788
},
8889
{
8990
Version: "1.7.5",
9091
Flavor: IstioDistributionFlavorTetrate,
9192
FlavorVersion: 0,
9293
K8SVersions: []string{"1.16"},
94+
EndOfLife: "2022-01-01",
9395
},
9496
},
9597
}
9698

9799
buf := logger.ExecuteWithLock(func() {
98100
require.NoError(t, PrintManifest(manifest, nil))
99101
})
100-
require.Equal(t, `ISTIO VERSION FLAVOR FLAVOR VERSION K8S VERSIONS
101-
1.7.6 tetrate 0 1.16
102-
1.7.5 tetrate 0 1.16
102+
require.Equal(t, `ISTIO VERSION FLAVOR FLAVOR VERSION K8S VERSIONS END OF LIFE
103+
1.7.6 tetrate 0 1.16 2022-01-01
104+
1.7.5 tetrate 0 1.16 2022-01-01
103105
`,
104106
buf.String())
105107
})
@@ -118,18 +120,21 @@ func TestPrintManifest(t *testing.T) {
118120
Flavor: IstioDistributionFlavorIstio,
119121
FlavorVersion: 0,
120122
K8SVersions: []string{"1.18"},
123+
EndOfLife: "2023-01-01",
121124
},
122125
{
123126
Version: "1.7.6",
124127
Flavor: IstioDistributionFlavorTetrateFIPS,
125128
FlavorVersion: 0,
126129
K8SVersions: []string{"1.16"},
130+
EndOfLife: "2022-01-01",
127131
},
128132
{
129133
Version: "1.7.5",
130134
Flavor: IstioDistributionFlavorTetrate,
131135
FlavorVersion: 0,
132136
K8SVersions: []string{"1.16"},
137+
EndOfLife: "2022-01-01",
133138
},
134139
},
135140
}
@@ -138,10 +143,10 @@ func TestPrintManifest(t *testing.T) {
138143
require.NoError(t, PrintManifest(manifest, current))
139144
})
140145

141-
require.Equal(t, `ISTIO VERSION FLAVOR FLAVOR VERSION K8S VERSIONS
142-
1.8.3 istio 0 1.18
143-
*1.7.6 tetratefips 0 1.16
144-
1.7.5 tetrate 0 1.16
146+
require.Equal(t, `ISTIO VERSION FLAVOR FLAVOR VERSION K8S VERSIONS END OF LIFE
147+
1.8.3 istio 0 1.18 2023-01-01
148+
*1.7.6 tetratefips 0 1.16 2022-01-01
149+
1.7.5 tetrate 0 1.16 2022-01-01
145150
`,
146151
buf.String())
147152
})

internal/manifest/type.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import (
1919
"strconv"
2020
"strings"
2121
"time"
22+
23+
"github.com/Masterminds/semver"
2224
)
2325

2426
type Manifest struct {
@@ -42,6 +44,8 @@ type IstioDistribution struct {
4244
IsSecurityPatch bool `json:"is_security_patch,omitempty"`
4345
// Release notes for this distribution.
4446
ReleaseNotes []string `json:"release_notes,omitempty"`
47+
// EndOfLife of this distribution (format: "YYYY-MM-DD")
48+
EndOfLife string `json:"end_of_life,omitempty"`
4549
}
4650

4751
const (
@@ -62,6 +66,25 @@ func (x *Manifest) GetEOLDates() (map[string]time.Time, error) {
6266
return ret, nil
6367
}
6468

69+
func (x *Manifest) SetEOLInIstioDistributions() error {
70+
for _, dist := range x.IstioDistributions {
71+
iVer, err := semver.NewVersion(dist.Version)
72+
if err != nil {
73+
return err
74+
}
75+
for v, date := range x.IstioMinorVersionsEOLDates {
76+
dVer, err := semver.NewVersion(v)
77+
if err != nil {
78+
return err
79+
}
80+
if (dVer.Major() == iVer.Major()) && (dVer.Minor() == iVer.Minor()) {
81+
dist.EndOfLife = date
82+
}
83+
}
84+
}
85+
return nil
86+
}
87+
6588
func parseManifestEOLDate(in string) (time.Time, error) {
6689
const layout = "2006-01-02"
6790
return time.Parse(layout, in)

internal/manifest/type_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,3 +580,29 @@ func TestGetLatestDistribution(t *testing.T) {
580580
})
581581
}
582582
}
583+
584+
func TestEOLInIstioDistributions(t *testing.T) {
585+
ms := &Manifest{
586+
IstioDistributions: []*IstioDistribution{
587+
{
588+
Version: "1.8.1",
589+
Flavor: IstioDistributionFlavorTetrate,
590+
FlavorVersion: 10,
591+
K8SVersions: []string{"1.16"},
592+
},
593+
{
594+
Version: "1.7.5",
595+
Flavor: IstioDistributionFlavorTetrate,
596+
FlavorVersion: 0,
597+
K8SVersions: []string{"1.16"},
598+
},
599+
},
600+
IstioMinorVersionsEOLDates: map[string]string{
601+
"1.7": "2022-01-01",
602+
"1.8": "2023-01-01",
603+
},
604+
}
605+
require.NoError(t, ms.SetEOLInIstioDistributions())
606+
require.Equal(t, "2023-01-01", ms.IstioDistributions[0].EndOfLife)
607+
require.Equal(t, "2022-01-01", ms.IstioDistributions[1].EndOfLife)
608+
}

0 commit comments

Comments
 (0)