Skip to content

Commit f8f1e25

Browse files
committed
feat: remove legacy monorepo-related code
1 parent 3378e1e commit f8f1e25

File tree

11 files changed

+2054
-258
lines changed

11 files changed

+2054
-258
lines changed

cmd/nomos/status/client.go

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -164,67 +164,10 @@ func (c *ClusterClient) clusterStatus(ctx context.Context, cluster, namespace st
164164
cs.Error = c.namespaceRepoClusterStatus(ctx, cs, namespace)
165165
} else if isOss || (cs.isMulti != nil && *cs.isMulti) {
166166
c.multiRepoClusterStatus(ctx, cs)
167-
} else {
168-
c.monoRepoClusterStatus(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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,10 @@ func clusterStates(ctx context.Context, clientMap map[string]*ClusterClient) (ma
148148
stateMap[name] = unavailableCluster(name)
149149
} else {
150150
cs := client.clusterStatus(ctx, name, namespace)
151-
stateMap[name] = cs
152151
if cs.isMulti != nil && !*cs.isMulti {
153152
monoRepoClusters = append(monoRepoClusters, name)
153+
} else {
154+
stateMap[name] = cs
154155
}
155156
}
156157
}

pkg/bugreport/bugreport.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const (
6565
// bug report
6666
type BugReporter struct {
6767
client client.Reader
68-
clientSet *kubernetes.Clientset
68+
clientSet kubernetes.Interface
6969
cm *unstructured.Unstructured
7070
enabled map[Product]bool
7171
util.ConfigManagementClient
@@ -79,7 +79,7 @@ type BugReporter struct {
7979
}
8080

8181
// New creates a new BugReport
82-
func New(ctx context.Context, c client.Client, cs *kubernetes.Clientset) (*BugReporter, error) {
82+
func New(ctx context.Context, c client.Client, cs kubernetes.Interface) (*BugReporter, error) {
8383
cm := &unstructured.Unstructured{}
8484
cm.SetGroupVersionKind(schema.GroupVersionKind{
8585
Group: configmanagement.GroupName,
@@ -94,22 +94,23 @@ func New(ctx context.Context, c client.Client, cs *kubernetes.Clientset) (*BugRe
9494
errorList = append(errorList, err)
9595
}
9696

97-
if err := c.Get(ctx, types.NamespacedName{Name: util.ConfigManagementName}, cm); err != nil {
97+
err = c.Get(ctx, types.NamespacedName{Name: util.ConfigManagementName}, cm)
98+
99+
if err != nil {
98100
if meta.IsNoMatchError(err) {
99101
fmt.Println("kind <<" + configmanagement.OperatorKind + ">> is not registered with the cluster")
100102
} else if errors.IsNotFound(err) {
101103
fmt.Println("ConfigManagement object not found")
102104
} else {
103105
errorList = append(errorList, err)
104106
}
105-
}
106-
107-
isMulti, _, err := unstructured.NestedBool(cm.UnstructuredContent(), "spec", "enableMultiRepo")
108-
if err != nil {
109-
fmt.Println("ConfigManagement parsing error", err)
110-
}
111-
if !isMulti {
112-
util.MonoRepoNotice(os.Stdout, currentk8sContext)
107+
} else {
108+
isMulti, _, err := unstructured.NestedBool(cm.UnstructuredContent(), "spec", "enableMultiRepo")
109+
if err != nil {
110+
fmt.Println("ConfigManagement parsing error", err)
111+
} else if !isMulti {
112+
util.MonoRepoNotice(os.Stdout, currentk8sContext)
113+
}
113114
}
114115

115116
return &BugReporter{
@@ -282,7 +283,7 @@ type resourcesToReadables func(*unstructured.UnstructuredList, string) []Readabl
282283
// fetchResources provides a set of Readables for resources with a given group and version
283284
// toReadables: the function that converts the resources to readables.
284285
func (b *BugReporter) fetchResources(ctx context.Context, gv schema.GroupVersion, toReadables resourcesToReadables) (rd []Readable) {
285-
rl, err := b.clientSet.ServerResourcesForGroupVersion(gv.String())
286+
rl, err := b.clientSet.Discovery().ServerResourcesForGroupVersion(gv.String())
286287
if err != nil {
287288
if errors.IsNotFound(err) {
288289
fmt.Printf("No %s resources found on cluster\n", gv.Group)

0 commit comments

Comments
 (0)