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

feat: Add replicas info item to ReplicaSet node (#16769) #16782

Closed
wants to merge 12 commits into from
10 changes: 10 additions & 0 deletions controller/cache/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ func populateNodeInfo(un *unstructured.Unstructured, res *ResourceInfo, customLa
populatePodInfo(un, res)
case kube.ServiceKind:
populateServiceInfo(un, res)
case kube.ReplicaSetKind:
populateReplicaSetInfo(un, res)
case "Node":
populateHostNodeInfo(un, res)
}
Expand Down Expand Up @@ -103,6 +105,14 @@ func populateServiceInfo(un *unstructured.Unstructured, res *ResourceInfo) {
res.NetworkingInfo = &v1alpha1.ResourceNetworkingInfo{TargetLabels: targetLabels, Ingress: ingress, ExternalURLs: urls}
}

func populateReplicaSetInfo(un *unstructured.Unstructured, res *ResourceInfo) {
// due to https://github.com/kubernetes-sigs/yaml/issues/45, replicas is parsed as a float
replicas, ok, err := unstructured.NestedFloat64(un.Object, "spec", "replicas")
if err == nil && ok {
res.Info = append(res.Info, v1alpha1.InfoItem{Name: "Replicas", Value: fmt.Sprintf("Replicas:%d", int(replicas))})
}
}

func getServiceName(backend map[string]interface{}, gvk schema.GroupVersionKind) (string, error) {
switch gvk.Group {
case "extensions":
Expand Down
16 changes: 16 additions & 0 deletions controller/cache/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -754,3 +754,19 @@ func TestManifestHash(t *testing.T) {
assert.Equal(t, expected, hash)
assert.Nil(t, err)
}

func TestReplicaSet(t *testing.T) {
replicaSet := strToUnstructured(`
apiVersion: v1
kind: ReplicaSet
metadata:
name: helm-guestbook
spec:
replicas: 10
`)

info := &ResourceInfo{}
populateNodeInfo(replicaSet, info, []string{})

assert.Contains(t, info.Info, v1alpha1.InfoItem{Name: "Replicas", Value: "Replicas:10"})
}
2 changes: 1 addition & 1 deletion controller/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ func (m *appStateManager) CompareAppState(app *v1alpha1.Application, project *v1
conditions = append(conditions, v1alpha1.ApplicationCondition{Type: v1alpha1.ApplicationConditionUnknownError, Message: err.Error(), LastTransitionTime: &now})
}
diffConfigBuilder.WithGVKParser(gvkParser)
diffConfigBuilder.WithManager(common.ArgoCDSSAManager)
diffConfigBuilder.WithManager(app.GetName() + "-" + app.GetNamespace())

diffConfigBuilder.WithServerSideDiff(serverSideDiff)

Expand Down
3 changes: 1 addition & 2 deletions controller/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"sync/atomic"
"time"

cdcommon "github.com/argoproj/argo-cd/v2/common"
"k8s.io/apimachinery/pkg/util/strategicpatch"

"github.com/argoproj/gitops-engine/pkg/sync"
Expand Down Expand Up @@ -322,7 +321,7 @@ func (m *appStateManager) SyncAppState(app *v1alpha1.Application, state *v1alpha
sync.WithPrunePropagationPolicy(&prunePropagationPolicy),
sync.WithReplace(syncOp.SyncOptions.HasOption(common.SyncOptionReplace)),
sync.WithServerSideApply(syncOp.SyncOptions.HasOption(common.SyncOptionServerSideApply)),
sync.WithServerSideApplyManager(cdcommon.ArgoCDSSAManager),
sync.WithServerSideApplyManager(app.GetName() + "-" + app.GetNamespace()),
}

if syncOp.SyncOptions.HasOption("CreateNamespace=true") {
Expand Down
2 changes: 1 addition & 1 deletion server/application/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -1939,7 +1939,7 @@ func (s *Server) Rollback(ctx context.Context, rollbackReq *application.Applicat
DryRun: rollbackReq.GetDryRun(),
Prune: rollbackReq.GetPrune(),
SyncOptions: syncOptions,
SyncStrategy: &appv1.SyncStrategy{Apply: &appv1.SyncStrategyApply{}},
SyncStrategy: &appv1.SyncStrategy{},
Source: &deploymentInfo.Source,
},
InitiatedBy: appv1.OperationInitiator{Username: session.Username(ctx)},
Expand Down
Loading