Skip to content

Commit c31e762

Browse files
committed
refactor: remove legacy monorepo-related code
1 parent 5ca3730 commit c31e762

File tree

8 files changed

+22
-311
lines changed

8 files changed

+22
-311
lines changed

cmd/nomos/status/client.go

Lines changed: 1 addition & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -162,69 +162,12 @@ func (c *ClusterClient) clusterStatus(ctx context.Context, cluster, namespace st
162162
cs.Error = c.rootRepoClusterStatus(ctx, cs)
163163
} else if namespace != "" {
164164
cs.Error = c.namespaceRepoClusterStatus(ctx, cs, namespace)
165-
} else if isOss || (cs.isMulti != nil && *cs.isMulti) {
166-
c.multiRepoClusterStatus(ctx, cs)
167165
} else {
168-
c.monoRepoClusterStatus(ctx, cs)
166+
c.multiRepoClusterStatus(ctx, cs)
169167
}
170168
return cs
171169
}
172170

173-
// monoRepoClusterStatus populates the given ClusterState with the sync status of
174-
// the mono repo on the ClusterClient's cluster.
175-
func (c *ClusterClient) monoRepoClusterStatus(ctx context.Context, cs *ClusterState) {
176-
git, err := c.monoRepoGit(ctx)
177-
if err != nil {
178-
cs.status = util.ErrorMsg
179-
cs.Error = err.Error()
180-
return
181-
}
182-
183-
repoList, err := c.repos.List(ctx, metav1.ListOptions{})
184-
if err != nil {
185-
cs.status = util.ErrorMsg
186-
cs.Error = err.Error()
187-
return
188-
}
189-
190-
if len(repoList.Items) == 0 {
191-
cs.status = util.UnknownMsg
192-
cs.Error = "Repo resource is missing"
193-
return
194-
}
195-
196-
repoStatus := repoList.Items[0].Status
197-
cs.repos = append(cs.repos, monoRepoStatus(git, repoStatus))
198-
}
199-
200-
// monoRepoGit fetches the mono repo ConfigManagement resource from the cluster
201-
// and builds a Git config out of it.
202-
func (c *ClusterClient) monoRepoGit(ctx context.Context) (*v1beta1.Git, error) {
203-
syncRepo, err := c.ConfigManagement.NestedString(ctx, "spec", "git", "syncRepo")
204-
if err != nil {
205-
return nil, err
206-
}
207-
syncBranch, err := c.ConfigManagement.NestedString(ctx, "spec", "git", "syncBranch")
208-
if err != nil {
209-
return nil, err
210-
}
211-
syncRev, err := c.ConfigManagement.NestedString(ctx, "spec", "git", "syncRev")
212-
if err != nil {
213-
return nil, err
214-
}
215-
policyDir, err := c.ConfigManagement.NestedString(ctx, "spec", "git", "policyDir")
216-
if err != nil {
217-
return nil, err
218-
}
219-
220-
return &v1beta1.Git{
221-
Repo: syncRepo,
222-
Branch: syncBranch,
223-
Revision: syncRev,
224-
Dir: policyDir,
225-
}, nil
226-
}
227-
228171
// syncingConditionSupported checks if the ACM version is v1.9.2 or later, which
229172
// has the high-level syncing condition.
230173
func (c *ClusterClient) syncingConditionSupported(ctx context.Context) bool {

cmd/nomos/status/cluster_state.go

Lines changed: 0 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2525
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2626
"kpt.dev/configsync/cmd/nomos/util"
27-
v1 "kpt.dev/configsync/pkg/api/configmanagement/v1"
2827
"kpt.dev/configsync/pkg/api/configsync"
2928
"kpt.dev/configsync/pkg/api/configsync/v1beta1"
3029
"kpt.dev/configsync/pkg/reposync"
@@ -197,112 +196,6 @@ func helmString(helm *v1beta1.HelmBase) string {
197196
return helmStr
198197
}
199198

200-
// monoRepoStatus converts the given Git config and mono-repo status into a RepoState.
201-
func monoRepoStatus(git *v1beta1.Git, status v1.RepoStatus) *RepoState {
202-
errors := syncStatusErrors(status)
203-
totalErrorCount := len(errors)
204-
205-
result := &RepoState{
206-
scope: "<root>",
207-
git: git,
208-
status: getSyncStatus(status),
209-
commit: commitHash(status.Sync.LatestToken),
210-
errors: errors,
211-
}
212-
213-
if totalErrorCount > 0 {
214-
result.errorSummary = &v1beta1.ErrorSummary{
215-
TotalCount: totalErrorCount,
216-
Truncated: false,
217-
ErrorCountAfterTruncation: totalErrorCount,
218-
}
219-
}
220-
return result
221-
}
222-
223-
// getSyncStatus returns the given RepoStatus formatted as a short summary string.
224-
func getSyncStatus(status v1.RepoStatus) string {
225-
if hasErrors(status) {
226-
return util.ErrorMsg
227-
}
228-
if len(status.Sync.LatestToken) == 0 {
229-
return pendingMsg
230-
}
231-
if status.Sync.LatestToken == status.Source.Token && len(status.Sync.InProgress) == 0 {
232-
return syncedMsg
233-
}
234-
return pendingMsg
235-
}
236-
237-
// hasErrors returns true if there are any config management errors present in the given RepoStatus.
238-
func hasErrors(status v1.RepoStatus) bool {
239-
if len(status.Import.Errors) > 0 {
240-
return true
241-
}
242-
for _, syncStatus := range status.Sync.InProgress {
243-
if len(syncStatus.Errors) > 0 {
244-
return true
245-
}
246-
}
247-
return false
248-
}
249-
250-
// syncStatusErrors returns all errors reported in the given RepoStatus as a single array.
251-
func syncStatusErrors(status v1.RepoStatus) []string {
252-
var errs []string
253-
for _, err := range status.Source.Errors {
254-
errs = append(errs, err.ErrorMessage)
255-
}
256-
for _, err := range status.Import.Errors {
257-
errs = append(errs, err.ErrorMessage)
258-
}
259-
for _, syncStatus := range status.Sync.InProgress {
260-
for _, err := range syncStatus.Errors {
261-
errs = append(errs, err.ErrorMessage)
262-
}
263-
}
264-
265-
if getResourceStatus(status.Sync.ResourceConditions) != v1.ResourceStateHealthy {
266-
errs = append(errs, getResourceStatusErrors(status.Sync.ResourceConditions)...)
267-
}
268-
269-
return errs
270-
}
271-
272-
func getResourceStatus(resourceConditions []v1.ResourceCondition) v1.ResourceConditionState {
273-
resourceStatus := v1.ResourceStateHealthy
274-
275-
for _, resourceCondition := range resourceConditions {
276-
277-
if resourceCondition.ResourceState.IsError() {
278-
return v1.ResourceStateError
279-
} else if resourceCondition.ResourceState.IsReconciling() {
280-
resourceStatus = v1.ResourceStateReconciling
281-
}
282-
}
283-
284-
return resourceStatus
285-
}
286-
287-
func getResourceStatusErrors(resourceConditions []v1.ResourceCondition) []string {
288-
if len(resourceConditions) == 0 {
289-
return nil
290-
}
291-
292-
var syncErrors []string
293-
294-
for _, resourceCondition := range resourceConditions {
295-
for _, rcError := range resourceCondition.Errors {
296-
syncErrors = append(syncErrors, fmt.Sprintf("%v\t%v\tError: %v", resourceCondition.Kind, resourceCondition.NamespacedName, rcError))
297-
}
298-
for _, rcReconciling := range resourceCondition.ReconcilingReasons {
299-
syncErrors = append(syncErrors, fmt.Sprintf("%v\t%v\tReconciling: %v", resourceCondition.Kind, resourceCondition.NamespacedName, rcReconciling))
300-
}
301-
}
302-
303-
return syncErrors
304-
}
305-
306199
// namespaceRepoStatus converts the given RepoSync into a RepoState.
307200
func namespaceRepoStatus(rs *v1beta1.RepoSync, rg *unstructured.Unstructured, syncingConditionSupported bool) *RepoState {
308201
repostate := &RepoState{

cmd/nomos/status/cluster_state_test.go

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2424
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2525
"kpt.dev/configsync/cmd/nomos/util"
26-
v1 "kpt.dev/configsync/pkg/api/configmanagement/v1"
2726
"kpt.dev/configsync/pkg/api/configsync"
2827
"kpt.dev/configsync/pkg/api/configsync/v1beta1"
2928
"kpt.dev/configsync/pkg/core"
@@ -359,86 +358,6 @@ func TestRepoState_PrintRows(t *testing.T) {
359358
}
360359
}
361360

362-
func TestRepoState_MonoRepoStatus(t *testing.T) {
363-
testCases := []struct {
364-
name string
365-
git *v1beta1.Git
366-
status v1.RepoStatus
367-
want *RepoState
368-
}{
369-
{
370-
"repo is pending first sync",
371-
git,
372-
v1.RepoStatus{
373-
Source: v1.RepoSourceStatus{},
374-
Import: v1.RepoImportStatus{},
375-
Sync: v1.RepoSyncStatus{},
376-
},
377-
&RepoState{
378-
scope: "<root>",
379-
git: git,
380-
status: "PENDING",
381-
commit: "N/A",
382-
},
383-
},
384-
{
385-
"repo is synced",
386-
git,
387-
v1.RepoStatus{
388-
Source: v1.RepoSourceStatus{
389-
Token: "abc123",
390-
},
391-
Import: v1.RepoImportStatus{
392-
Token: "abc123",
393-
},
394-
Sync: v1.RepoSyncStatus{
395-
LatestToken: "abc123",
396-
},
397-
},
398-
&RepoState{
399-
scope: "<root>",
400-
git: git,
401-
status: "SYNCED",
402-
commit: "abc123",
403-
},
404-
},
405-
{
406-
"repo has errors",
407-
git,
408-
v1.RepoStatus{
409-
Source: v1.RepoSourceStatus{
410-
Token: "def456",
411-
},
412-
Import: v1.RepoImportStatus{
413-
Token: "def456",
414-
Errors: []v1.ConfigManagementError{
415-
{ErrorMessage: "KNV2010: I am unhappy"},
416-
},
417-
},
418-
Sync: v1.RepoSyncStatus{
419-
LatestToken: "abc123",
420-
},
421-
},
422-
&RepoState{
423-
scope: "<root>",
424-
git: git,
425-
status: "ERROR",
426-
commit: "abc123",
427-
errors: []string{"KNV2010: I am unhappy"},
428-
errorSummary: errorSummayWithOneError,
429-
},
430-
},
431-
}
432-
for _, tc := range testCases {
433-
t.Run(tc.name, func(t *testing.T) {
434-
got := monoRepoStatus(tc.git, tc.status)
435-
if diff := cmp.Diff(tc.want, got, cmp.AllowUnexported(*tc.want)); diff != "" {
436-
t.Error(diff)
437-
}
438-
})
439-
}
440-
}
441-
442361
func toGitStatus(git *v1beta1.Git) *v1beta1.GitStatus {
443362
return &v1beta1.GitStatus{
444363
Repo: git.Repo,

cmd/nomos/status/status.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -139,22 +139,18 @@ func clusterNames(clientMap map[string]*ClusterClient) []string {
139139
}
140140

141141
// clusterStates returns a map of clusterStates calculated from the given map of
142-
// clients, and a list of clusters running in the mono-repo mode.
143-
func clusterStates(ctx context.Context, clientMap map[string]*ClusterClient) (map[string]*ClusterState, []string) {
142+
// clients
143+
func clusterStates(ctx context.Context, clientMap map[string]*ClusterClient) map[string]*ClusterState {
144144
stateMap := make(map[string]*ClusterState)
145-
var monoRepoClusters []string
146145
for name, client := range clientMap {
147146
if client == nil {
148147
stateMap[name] = unavailableCluster(name)
149148
} else {
150149
cs := client.clusterStatus(ctx, name, namespace)
151150
stateMap[name] = cs
152-
if cs.isMulti != nil && !*cs.isMulti {
153-
monoRepoClusters = append(monoRepoClusters, name)
154-
}
155151
}
156152
}
157-
return stateMap, monoRepoClusters
153+
return stateMap
158154
}
159155

160156
// printStatus fetches ConfigManagementStatus and/or RepoStatus from each cluster in the given map
@@ -163,10 +159,7 @@ func clusterStates(ctx context.Context, clientMap map[string]*ClusterClient) (ma
163159
// nolint:errcheck
164160
func printStatus(ctx context.Context, writer *tabwriter.Writer, clientMap map[string]*ClusterClient, names []string) {
165161
// First build up a map of all the states to display.
166-
stateMap, monoRepoClusters := clusterStates(ctx, clientMap)
167-
168-
// Log a notice for the detected clusters that are running in the mono-repo mode.
169-
util.MonoRepoNotice(writer, monoRepoClusters...)
162+
stateMap := clusterStates(ctx, clientMap)
170163

171164
currentContext, err := restconfig.CurrentContextName()
172165
if err != nil {

cmd/nomos/util/util.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package util
1717
import (
1818
"fmt"
1919
"io"
20-
"strings"
2120
)
2221

2322
const (
@@ -40,21 +39,6 @@ const (
4039
ColorCyan = "\033[36m"
4140
)
4241

43-
// MonoRepoNotice logs a notice for the clusters that are running in the legacy mode.
44-
func MonoRepoNotice(writer io.Writer, monoRepoClusters ...string) {
45-
clusterCount := len(monoRepoClusters)
46-
if clusterCount != 0 {
47-
if clusterCount == 1 {
48-
MustFprintf(writer, "%sNotice: The cluster %q is still running in the legacy mode.\n",
49-
ColorYellow, monoRepoClusters[0])
50-
} else {
51-
MustFprintf(writer, "%sNotice: The following clusters are still running in the legacy mode:\n%s%s\n",
52-
ColorYellow, Bullet, strings.Join(monoRepoClusters, "\n"+Bullet))
53-
}
54-
MustFprintf(writer, "Run `nomos migrate` to enable multi-repo mode. It provides you with additional features and gives you the flexibility to sync to a single repository, or multiple repositories.%s\n", ColorDefault)
55-
}
56-
}
57-
5842
// MustFprintf prints a formatted string to the writer and panics on error.
5943
func MustFprintf(w io.Writer, format string, a ...any) {
6044
if _, err := fmt.Fprintf(w, format, a...); err != nil {

0 commit comments

Comments
 (0)