From 5d6fd8fc592dc1101b5949b032cb10ce83699086 Mon Sep 17 00:00:00 2001 From: Waldemar Date: Tue, 30 Sep 2025 11:33:52 +0200 Subject: [PATCH] chore(cli): Removed appName from config schema. This is redundant to metadata name --- apply.md | 3 +- internal/apply/manager.go | 2 +- internal/apply/manager_test.go | 1 - internal/apply/planner.go | 5 ++- internal/apply/planner_test.go | 1 - internal/config/example_test.go | 10 +++--- internal/config/parser_test.go | 16 +-------- internal/config/types.go | 33 +------------------ .../comprehensive/EdgeConnectConfig.yaml | 11 +++---- 9 files changed, 14 insertions(+), 68 deletions(-) diff --git a/apply.md b/apply.md index d70d946..d722dc8 100644 --- a/apply.md +++ b/apply.md @@ -35,7 +35,6 @@ metadata: name: "edge-app-demo" spec: k8sApp: # App definition - appName: "edge-app-demo" appVersion: "1.0.0" manifestFile: "./k8s-deployment.yaml" infraTemplate: # Instance deployment targets @@ -330,4 +329,4 @@ examples/apply/ └── with-network.yaml # Network configuration example ``` -This blueprint provides a systematic approach to implementing the apply command while maintaining consistency with existing CLI patterns and ensuring robust error handling and user experience. \ No newline at end of file +This blueprint provides a systematic approach to implementing the apply command while maintaining consistency with existing CLI patterns and ensuring robust error handling and user experience. diff --git a/internal/apply/manager.go b/internal/apply/manager.go index 72145c6..21661c6 100644 --- a/internal/apply/manager.go +++ b/internal/apply/manager.go @@ -335,7 +335,7 @@ func (rm *EdgeConnectResourceManager) createInstance(ctx context.Context, action }, AppKey: edgeconnect.AppKey{ Organization: action.Target.Organization, - Name: config.Spec.GetAppName(), + Name: config.Metadata.Name, Version: config.Spec.GetAppVersion(), }, Flavor: edgeconnect.Flavor{ diff --git a/internal/apply/manager_test.go b/internal/apply/manager_test.go index 5055200..bbc2aa2 100644 --- a/internal/apply/manager_test.go +++ b/internal/apply/manager_test.go @@ -131,7 +131,6 @@ func createTestManagerConfig(t *testing.T) *config.EdgeConnectConfig { }, Spec: config.Spec{ K8sApp: &config.K8sApp{ - AppName: "test-app", AppVersion: "1.0.0", ManifestFile: manifestFile, }, diff --git a/internal/apply/planner.go b/internal/apply/planner.go index b4b55de..0c94f85 100644 --- a/internal/apply/planner.go +++ b/internal/apply/planner.go @@ -131,7 +131,7 @@ func (p *EdgeConnectPlanner) planAppAction(ctx context.Context, config *config.E // Build desired app state desired := &AppState{ - Name: config.Spec.GetAppName(), + Name: config.Metadata.Name, Version: config.Spec.GetAppVersion(), Organization: config.Spec.InfraTemplate[0].Organization, // Use first infra template for org Region: config.Spec.InfraTemplate[0].Region, // Use first infra template for region @@ -204,11 +204,10 @@ func (p *EdgeConnectPlanner) planInstanceActions(ctx context.Context, config *co var warnings []string for _, infra := range config.Spec.InfraTemplate { - instanceName := getInstanceName(config.Spec.GetAppName(), config.Spec.GetAppVersion()) + instanceName := getInstanceName(config.Metadata.Name, config.Spec.GetAppVersion()) desired := &InstanceState{ Name: instanceName, - AppName: config.Spec.GetAppName(), AppVersion: config.Spec.GetAppVersion(), Organization: infra.Organization, Region: infra.Region, diff --git a/internal/apply/planner_test.go b/internal/apply/planner_test.go index 5855b06..7efb888 100644 --- a/internal/apply/planner_test.go +++ b/internal/apply/planner_test.go @@ -106,7 +106,6 @@ func createTestConfig(t *testing.T) *config.EdgeConnectConfig { }, Spec: config.Spec{ K8sApp: &config.K8sApp{ - AppName: "test-app", AppVersion: "1.0.0", ManifestFile: manifestFile, }, diff --git a/internal/config/example_test.go b/internal/config/example_test.go index d0fb2c9..2cc4f27 100644 --- a/internal/config/example_test.go +++ b/internal/config/example_test.go @@ -14,7 +14,7 @@ func TestParseExampleConfig(t *testing.T) { parser := NewParser() // Parse the actual example file (now that we've created the manifest file) - examplePath := filepath.Join("../examples/comprehensive/EdgeConnectConfig.yaml") + examplePath := filepath.Join("../../sdk/examples/comprehensive/EdgeConnectConfig.yaml") config, err := parser.ParseFile(examplePath) // This should now succeed with full validation @@ -27,7 +27,6 @@ func TestParseExampleConfig(t *testing.T) { // Check k8s app configuration require.NotNil(t, config.Spec.K8sApp) - assert.Equal(t, "edge-app-demo", config.Spec.K8sApp.AppName) assert.Equal(t, "1.0.0", config.Spec.K8sApp.AppVersion) // Note: ManifestFile path should be resolved to absolute path assert.Contains(t, config.Spec.K8sApp.ManifestFile, "k8s-deployment.yaml") @@ -58,14 +57,14 @@ func TestParseExampleConfig(t *testing.T) { assert.Equal(t, "0.0.0.0/0", conn2.RemoteCIDR) // Test utility methods - assert.Equal(t, "edge-app-demo", config.Spec.GetAppName()) + assert.Equal(t, "edge-app-demo", config.Metadata.Name) assert.Equal(t, "1.0.0", config.Spec.GetAppVersion()) assert.Contains(t, config.Spec.GetManifestFile(), "k8s-deployment.yaml") assert.True(t, config.Spec.IsK8sApp()) assert.False(t, config.Spec.IsDockerApp()) // Test instance name generation - instanceName := GetInstanceName(config.Spec.GetAppName(), config.Spec.GetAppVersion()) + instanceName := GetInstanceName(config.Metadata.Name, config.Spec.GetAppVersion()) assert.Equal(t, "edge-app-demo-1.0.0-instance", instanceName) } @@ -80,7 +79,6 @@ func TestValidateExampleStructure(t *testing.T) { }, Spec: Spec{ DockerApp: &DockerApp{ // Use DockerApp to avoid manifest file validation - AppName: "edge-app-demo", AppVersion: "1.0.0", Image: "nginx:latest", }, @@ -127,4 +125,4 @@ func TestValidateExampleStructure(t *testing.T) { // Test port range validation err = parser.ValidatePortRanges(config) assert.NoError(t, err) -} \ No newline at end of file +} diff --git a/internal/config/parser_test.go b/internal/config/parser_test.go index 01bb222..79b149a 100644 --- a/internal/config/parser_test.go +++ b/internal/config/parser_test.go @@ -34,7 +34,6 @@ metadata: name: "test-app" spec: k8sApp: - appName: "test-app" appVersion: "1.0.0" manifestFile: "./test-manifest.yaml" infraTemplate: @@ -55,7 +54,6 @@ metadata: name: "test-app" spec: dockerApp: - appName: "test-app" appVersion: "1.0.0" image: "nginx:latest" infraTemplate: @@ -74,7 +72,6 @@ metadata: name: "test-app" spec: k8sApp: - appName: "test-app" appVersion: "1.0.0" manifestFile: "./test-manifest.yaml" infraTemplate: @@ -95,7 +92,6 @@ metadata: name: "test-app" spec: dockerApp: - appName: "test-app" appVersion: "1.0.0" image: "nginx:latest" infraTemplate: @@ -133,7 +129,6 @@ metadata: name: "test-app" spec: k8sApp: - appName: "test-app" appVersion: "1.0.0" manifestFile: "./test-manifest.yaml" dockerApp: @@ -158,7 +153,6 @@ metadata: name: "test-app" spec: dockerApp: - appName: "test-app" appVersion: "1.0.0" image: "nginx:latest" infraTemplate: [] @@ -174,7 +168,6 @@ metadata: name: "test-app" spec: dockerApp: - appName: "test-app" appVersion: "1.0.0" image: "nginx:latest" infraTemplate: @@ -231,7 +224,6 @@ metadata: name: "test-app" spec: dockerApp: - appName: "test-app" appVersion: "1.0.0" image: "nginx:latest" infraTemplate: @@ -294,7 +286,6 @@ metadata: name: "test-app" spec: k8sApp: - appName: "test-app" appVersion: "1.0.0" manifestFile: "./manifest.yaml" infraTemplate: @@ -334,7 +325,6 @@ func TestEdgeConnectConfig_Validate(t *testing.T) { }, Spec: Spec{ DockerApp: &DockerApp{ - AppName: "test-app", AppVersion: "1.0.0", Image: "nginx:latest", }, @@ -736,7 +726,6 @@ func TestGetInstanceName(t *testing.T) { func TestSpec_GetMethods(t *testing.T) { k8sSpec := &Spec{ K8sApp: &K8sApp{ - AppName: "k8s-app", AppVersion: "1.0.0", ManifestFile: "k8s.yaml", }, @@ -744,19 +733,16 @@ func TestSpec_GetMethods(t *testing.T) { dockerSpec := &Spec{ DockerApp: &DockerApp{ - AppName: "docker-app", AppVersion: "2.0.0", ManifestFile: "docker.yaml", }, } - assert.Equal(t, "k8s-app", k8sSpec.GetAppName()) assert.Equal(t, "1.0.0", k8sSpec.GetAppVersion()) assert.Equal(t, "k8s.yaml", k8sSpec.GetManifestFile()) assert.True(t, k8sSpec.IsK8sApp()) assert.False(t, k8sSpec.IsDockerApp()) - assert.Equal(t, "docker-app", dockerSpec.GetAppName()) assert.Equal(t, "2.0.0", dockerSpec.GetAppVersion()) assert.Equal(t, "docker.yaml", dockerSpec.GetManifestFile()) assert.False(t, dockerSpec.IsK8sApp()) @@ -786,4 +772,4 @@ func TestPortRangesOverlap(t *testing.T) { assert.Equal(t, tt.expected, result) }) } -} \ No newline at end of file +} diff --git a/internal/config/types.go b/internal/config/types.go index 653fb1a..3c4a4eb 100644 --- a/internal/config/types.go +++ b/internal/config/types.go @@ -31,14 +31,12 @@ type Spec struct { // K8sApp defines Kubernetes application configuration type K8sApp struct { - AppName string `yaml:"appName"` AppVersion string `yaml:"appVersion"` ManifestFile string `yaml:"manifestFile"` } // DockerApp defines Docker application configuration type DockerApp struct { - AppName string `yaml:"appName"` AppVersion string `yaml:"appVersion"` ManifestFile string `yaml:"manifestFile"` Image string `yaml:"image"` @@ -148,10 +146,6 @@ func (s *Spec) Validate() error { // Validate validates k8s app configuration func (k *K8sApp) Validate() error { - if k.AppName == "" { - return fmt.Errorf("appName is required") - } - if k.AppVersion == "" { return fmt.Errorf("appVersion is required") } @@ -165,11 +159,6 @@ func (k *K8sApp) Validate() error { return fmt.Errorf("manifestFile does not exist: %s", k.ManifestFile) } - // Validate app name format - if strings.TrimSpace(k.AppName) != k.AppName { - return fmt.Errorf("appName cannot have leading/trailing whitespace") - } - // Validate version format if strings.TrimSpace(k.AppVersion) != k.AppVersion { return fmt.Errorf("appVersion cannot have leading/trailing whitespace") @@ -180,10 +169,6 @@ func (k *K8sApp) Validate() error { // Validate validates docker app configuration func (d *DockerApp) Validate() error { - if d.AppName == "" { - return fmt.Errorf("appName is required") - } - if d.AppVersion == "" { return fmt.Errorf("appVersion is required") } @@ -192,11 +177,6 @@ func (d *DockerApp) Validate() error { return fmt.Errorf("image is required") } - // Validate app name format - if strings.TrimSpace(d.AppName) != d.AppName { - return fmt.Errorf("appName cannot have leading/trailing whitespace") - } - // Validate version format if strings.TrimSpace(d.AppVersion) != d.AppVersion { return fmt.Errorf("appVersion cannot have leading/trailing whitespace") @@ -321,17 +301,6 @@ func (d *DockerApp) GetManifestPath(configDir string) string { return filepath.Join(configDir, d.ManifestFile) } -// GetAppName returns the application name from the active app type -func (s *Spec) GetAppName() string { - if s.K8sApp != nil { - return s.K8sApp.AppName - } - if s.DockerApp != nil { - return s.DockerApp.AppName - } - return "" -} - // GetAppVersion returns the application version from the active app type func (s *Spec) GetAppVersion() string { if s.K8sApp != nil { @@ -362,4 +331,4 @@ func (s *Spec) IsK8sApp() bool { // IsDockerApp returns true if this is a Docker application func (s *Spec) IsDockerApp() bool { return s.DockerApp != nil -} \ No newline at end of file +} diff --git a/sdk/examples/comprehensive/EdgeConnectConfig.yaml b/sdk/examples/comprehensive/EdgeConnectConfig.yaml index b940145..37bde30 100644 --- a/sdk/examples/comprehensive/EdgeConnectConfig.yaml +++ b/sdk/examples/comprehensive/EdgeConnectConfig.yaml @@ -1,18 +1,15 @@ # Is there a swagger file for the new EdgeConnect API? -# - +# How does it differ from the EdgeXR API? kind: edgeconnect-deployment metadata: - name: "edge-app-demo" + name: "edge-app-demo" # name could be used for appName spec: - # dockerApp: - # appName: "edge-app-demo" + # dockerApp: # Docker is OBSOLETE # appVersion: "1.0.0" # manifestFile: "./docker-compose.yaml" # image: "https://registry-1.docker.io/library/nginx:latest" k8sApp: - appName: "edge-app-demo" # appinstance name is $appName-$appVersion-instance - appVersion: "1.0.1" + appVersion: "1.0.0" manifestFile: "./k8s-deployment.yaml" # store hash of the manifest file in annotation field. Annotations is a comma separated map of arbitrary key value pairs, infraTemplate: - organization: "edp2"