Skip to content

Commit

Permalink
chore: remove argocd-cm plugin support (#13755)
Browse files Browse the repository at this point in the history
  • Loading branch information
crenshaw-dev authored Jun 21, 2023
1 parent 150a184 commit 57b557d
Show file tree
Hide file tree
Showing 30 changed files with 373 additions and 442 deletions.
1 change: 1 addition & 0 deletions assets/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -4367,6 +4367,7 @@
"type": "boolean"
},
"configManagementPlugins": {
"description": "Deprecated: use sidecar plugins instead.",
"type": "array",
"items": {
"$ref": "#/definitions/v1alpha1ConfigManagementPlugin"
Expand Down
7 changes: 0 additions & 7 deletions cmd/argocd/commands/admin/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,6 @@ var validatorsByGroup = map[string]settingValidator{
_, err := manager.GetGoogleAnalytics()
return "", err
}),
"plugins": func(manager *settings.SettingsManager) (string, error) {
plugins, err := manager.GetConfigManagementPlugins()
if err != nil {
return "", err
}
return fmt.Sprintf("%d plugins", len(plugins)), nil
},
"kustomize": func(manager *settings.SettingsManager) (string, error) {
opts, err := manager.GetKustomizeSettings()
if err != nil {
Expand Down
7 changes: 0 additions & 7 deletions cmd/argocd/commands/admin/settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,6 @@ clientSecret: aaaabbbbccccddddeee`,
},
containsSummary: "Dex is configured ('url' field is missing)",
},
"Plugins_ValidConfig": {
validator: "plugins",
data: map[string]string{
"configManagementPlugins": `[{"name": "test1"}, {"name": "test2"}]`,
},
containsSummary: "2 plugins",
},
"Kustomize_ModifiedOptions": {
validator: "kustomize",
containsSummary: "default options",
Expand Down
19 changes: 9 additions & 10 deletions cmd/argocd/commands/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -845,8 +845,8 @@ func targetObjects(resources []*argoappv1.ResourceDiff) ([]*unstructured.Unstruc
}

func getLocalObjects(ctx context.Context, app *argoappv1.Application, proj *argoappv1.AppProject, local, localRepoRoot, appLabelKey, kubeVersion string, apiVersions []string, kustomizeOptions *argoappv1.KustomizeOptions,
configManagementPlugins []*argoappv1.ConfigManagementPlugin, trackingMethod string) []*unstructured.Unstructured {
manifestStrings := getLocalObjectsString(ctx, app, proj, local, localRepoRoot, appLabelKey, kubeVersion, apiVersions, kustomizeOptions, configManagementPlugins, trackingMethod)
trackingMethod string) []*unstructured.Unstructured {
manifestStrings := getLocalObjectsString(ctx, app, proj, local, localRepoRoot, appLabelKey, kubeVersion, apiVersions, kustomizeOptions, trackingMethod)
objs := make([]*unstructured.Unstructured, len(manifestStrings))
for i := range manifestStrings {
obj := unstructured.Unstructured{}
Expand All @@ -858,7 +858,7 @@ func getLocalObjects(ctx context.Context, app *argoappv1.Application, proj *argo
}

func getLocalObjectsString(ctx context.Context, app *argoappv1.Application, proj *argoappv1.AppProject, local, localRepoRoot, appLabelKey, kubeVersion string, apiVersions []string, kustomizeOptions *argoappv1.KustomizeOptions,
configManagementPlugins []*argoappv1.ConfigManagementPlugin, trackingMethod string) []string {
trackingMethod string) []string {
source := app.Spec.GetSource()
res, err := repository.GenerateManifests(ctx, local, localRepoRoot, source.TargetRevision, &repoapiclient.ManifestRequest{
Repo: &argoappv1.Repository{Repo: source.RepoURL},
Expand All @@ -869,7 +869,6 @@ func getLocalObjectsString(ctx context.Context, app *argoappv1.Application, proj
KustomizeOptions: kustomizeOptions,
KubeVersion: kubeVersion,
ApiVersions: apiVersions,
Plugins: configManagementPlugins,
TrackingMethod: trackingMethod,
ProjectName: proj.Name,
ProjectSourceRepos: proj.Spec.SourceRepos,
Expand Down Expand Up @@ -991,7 +990,7 @@ func NewApplicationDiffCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co
}
}
proj := getProject(c, clientOpts, ctx, app.Spec.Project)
foundDiffs := findandPrintDiff(ctx, app, proj.Project, resources, argoSettings, appName, diffOption)
foundDiffs := findandPrintDiff(ctx, app, proj.Project, resources, argoSettings, diffOption)
if foundDiffs && exitCode {
os.Exit(1)
}
Expand Down Expand Up @@ -1019,13 +1018,13 @@ type DifferenceOption struct {
}

// findandPrintDiff ... Prints difference between application current state and state stored in git or locally, returns boolean as true if difference is found else returns false
func findandPrintDiff(ctx context.Context, app *argoappv1.Application, proj *argoappv1.AppProject, resources *application.ManagedResourcesResponse, argoSettings *settings.Settings, appName string, diffOptions *DifferenceOption) bool {
func findandPrintDiff(ctx context.Context, app *argoappv1.Application, proj *argoappv1.AppProject, resources *application.ManagedResourcesResponse, argoSettings *settings.Settings, diffOptions *DifferenceOption) bool {
var foundDiffs bool
liveObjs, err := cmdutil.LiveObjects(resources.Items)
errors.CheckError(err)
items := make([]objKeyLiveTarget, 0)
if diffOptions.local != "" {
localObjs := groupObjsByKey(getLocalObjects(ctx, app, proj, diffOptions.local, diffOptions.localRepoRoot, argoSettings.AppLabelKey, diffOptions.cluster.Info.ServerVersion, diffOptions.cluster.Info.APIVersions, argoSettings.KustomizeOptions, argoSettings.ConfigManagementPlugins, argoSettings.TrackingMethod), liveObjs, app.Spec.Destination.Namespace)
localObjs := groupObjsByKey(getLocalObjects(ctx, app, proj, diffOptions.local, diffOptions.localRepoRoot, argoSettings.AppLabelKey, diffOptions.cluster.Info.ServerVersion, diffOptions.cluster.Info.APIVersions, argoSettings.KustomizeOptions, argoSettings.TrackingMethod), liveObjs, app.Spec.Destination.Namespace)
items = groupObjsForDiff(resources, localObjs, items, argoSettings, app.InstanceName(argoSettings.ControllerNamespace))
} else if diffOptions.revision != "" {
var unstructureds []*unstructured.Unstructured
Expand Down Expand Up @@ -1690,7 +1689,7 @@ func NewApplicationSyncCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co
argoio.Close(conn)

proj := getProject(c, clientOpts, ctx, app.Spec.Project)
localObjsStrings = getLocalObjectsString(ctx, app, proj.Project, local, localRepoRoot, argoSettings.AppLabelKey, cluster.Info.ServerVersion, cluster.Info.APIVersions, argoSettings.KustomizeOptions, argoSettings.ConfigManagementPlugins, argoSettings.TrackingMethod)
localObjsStrings = getLocalObjectsString(ctx, app, proj.Project, local, localRepoRoot, argoSettings.AppLabelKey, cluster.Info.ServerVersion, cluster.Info.APIVersions, argoSettings.KustomizeOptions, argoSettings.TrackingMethod)
errors.CheckError(err)
diffOption.local = local
diffOption.localRepoRoot = localRepoRoot
Expand Down Expand Up @@ -1761,7 +1760,7 @@ func NewApplicationSyncCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co
fmt.Printf("====== Previewing differences between live and desired state of application %s ======\n", appQualifiedName)

proj := getProject(c, clientOpts, ctx, app.Spec.Project)
foundDiffs = findandPrintDiff(ctx, app, proj.Project, resources, argoSettings, appQualifiedName, diffOption)
foundDiffs = findandPrintDiff(ctx, app, proj.Project, resources, argoSettings, diffOption)
if foundDiffs {
if !diffChangesConfirm {
yesno := cli.AskToProceed(fmt.Sprintf("Please review changes to application %s shown above. Do you want to continue the sync process? (y/n): ", appQualifiedName))
Expand Down Expand Up @@ -2374,7 +2373,7 @@ func NewApplicationManifestsCommand(clientOpts *argocdclient.ClientOptions) *cob
errors.CheckError(err)

proj := getProject(c, clientOpts, ctx, app.Spec.Project)
unstructureds = getLocalObjects(context.Background(), app, proj.Project, local, localRepoRoot, argoSettings.AppLabelKey, cluster.ServerVersion, cluster.Info.APIVersions, argoSettings.KustomizeOptions, argoSettings.ConfigManagementPlugins, argoSettings.TrackingMethod)
unstructureds = getLocalObjects(context.Background(), app, proj.Project, local, localRepoRoot, argoSettings.AppLabelKey, cluster.ServerVersion, cluster.Info.APIVersions, argoSettings.KustomizeOptions, argoSettings.TrackingMethod)
} else if revision != "" {
q := application.ApplicationManifestQuery{
Name: &appName,
Expand Down
215 changes: 215 additions & 0 deletions cmpserver/plugin/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
package plugin

import (
"fmt"
"os"
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/argoproj/argo-cd/v2/common"
)

func Test_IsDefined(t *testing.T) {
testCases := []struct {
name string
discover Discover
expected bool
}{
{
name: "empty discover",
discover: Discover{},
expected: false,
},
{
name: "discover with find",
discover: Discover{
Find: Find{
Glob: "glob",
},
},
expected: true,
},
{
name: "discover with fileName",
discover: Discover{
FileName: "fileName",
},
expected: true,
},
{
name: "discover with empty command",
discover: Discover{
Find: Find{
Command: Command{
Command: []string{},
},
},
},
expected: false,
},
{
name: "discover with command",
discover: Discover{
Find: Find{
Command: Command{
Command: []string{"command"},
},
},
},
expected: true,
},
}

for _, tc := range testCases {
tcc := tc
t.Run(tcc.name, func(t *testing.T) {
t.Parallel()

actual := tcc.discover.IsDefined()
assert.Equal(t, tcc.expected, actual)
})
}
}

func Test_ReadPluginConfig(t *testing.T) {
testCases := []struct {
name string
fileContents string
expected *PluginConfig
expectedErr string
}{
{
name: "empty metadata",
fileContents: `
metadata:
`,
expected: nil,
expectedErr: "invalid plugin configuration file. metadata.name should be non-empty.",
},
{
name: "empty metadata name",
fileContents: `
metadata:
name: ""
`,
expected: nil,
expectedErr: "invalid plugin configuration file. metadata.name should be non-empty.",
},
{
name: "invalid kind",
fileContents: `
kind: invalid
metadata:
name: name
`,
expected: nil,
expectedErr: "invalid plugin configuration file. kind should be ConfigManagementPlugin, found invalid",
},
{
name: "empty generate command",
fileContents: `
kind: ConfigManagementPlugin
metadata:
name: name
`,
expected: nil,
expectedErr: "invalid plugin configuration file. spec.generate command should be non-empty",
},
{
name: "valid config",
fileContents: `
kind: ConfigManagementPlugin
metadata:
name: name
spec:
generate:
command: [command]
`,
expected: &PluginConfig{
TypeMeta: v1.TypeMeta{
Kind: ConfigManagementPluginKind,
},
Metadata: v1.ObjectMeta{
Name: "name",
},
Spec: PluginConfigSpec{
Generate: Command{
Command: []string{"command"},
},
},
},
},
}

for _, tc := range testCases {
tcc := tc
t.Run(tcc.name, func(t *testing.T) {
t.Parallel()
// write test string to temporary file
tempDir := t.TempDir()
tempFile, err := os.Create(filepath.Join(tempDir, "plugin.yaml"))
require.NoError(t, err)
err = tempFile.Close()
require.NoError(t, err)
err = os.WriteFile(tempFile.Name(), []byte(tcc.fileContents), 0644)
require.NoError(t, err)
config, err := ReadPluginConfig(tempDir)
if tcc.expectedErr != "" {
assert.EqualError(t, err, tcc.expectedErr)
} else {
assert.NoError(t, err)
}
assert.Equal(t, tcc.expected, config)
})
}
}

func Test_PluginConfig_Address(t *testing.T) {
testCases := []struct {
name string
config *PluginConfig
expected string
}{
{
name: "no version specified",
config: &PluginConfig{
TypeMeta: v1.TypeMeta{
Kind: ConfigManagementPluginKind,
},
Metadata: v1.ObjectMeta{
Name: "name",
},
},
expected: "name",
},
{
name: "version specified",
config: &PluginConfig{
TypeMeta: v1.TypeMeta{
Kind: ConfigManagementPluginKind,
},
Metadata: v1.ObjectMeta{
Name: "name",
},
Spec: PluginConfigSpec{
Version: "version",
},
},
expected: "name-version",
},
}

for _, tc := range testCases {
tcc := tc
t.Run(tcc.name, func(t *testing.T) {
t.Parallel()
actual := tcc.config.Address()
expectedAddress := fmt.Sprintf("%s/%s.sock", common.GetPluginSockFilePath(), tcc.expected)
assert.Equal(t, expectedAddress, actual)
})
}
}
9 changes: 0 additions & 9 deletions controller/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,11 @@ func (m *appStateManager) getRepoObjs(app *v1alpha1.Application, sources []v1alp
return nil, nil, err
}

plugins, err := m.settingsMgr.GetConfigManagementPlugins()
if err != nil {
return nil, nil, err
}
enabledSourceTypes, err := m.settingsMgr.GetEnabledSourceTypes()
if err != nil {
return nil, nil, err
}
ts.AddCheckpoint("plugins_ms")
tools := make([]*v1alpha1.ConfigManagementPlugin, len(plugins))
for i := range plugins {
tools[i] = &plugins[i]
}

kustomizeSettings, err := m.settingsMgr.GetKustomizeSettings()
if err != nil {
Expand Down Expand Up @@ -198,7 +190,6 @@ func (m *appStateManager) getRepoObjs(app *v1alpha1.Application, sources []v1alp
AppName: app.InstanceName(m.namespace),
Namespace: app.Spec.Destination.Namespace,
ApplicationSource: &source,
Plugins: tools,
KustomizeOptions: kustomizeOptions,
KubeVersion: serverVersion,
ApiVersions: argo.APIResourcesToStrings(apiResources, true),
Expand Down
Loading

0 comments on commit 57b557d

Please sign in to comment.