Repository: fission/fission (language: go)

Issue:
Error on fission spec validate but application seems to work fine

<!-- Documentation URL: https://fission.io/docs -->
<!-- Troubleshooting guide: https://fission.io/docs/trouble-shooting/ -->

**Fission/Kubernetes version**

<!-- If you tested with other services, for example Istio, please also provide the version of service as well. -->

<pre>
$ fission version
client:
  fission/core:
    BuildDate: "2025-01-25T15:57:43Z"
    GitCommit: 2853498a
    Version: v1.21.0
server:
  fission/core:
    BuildDate: "2025-01-25T15:57:43Z"
    GitCommit: 2853498a
    Version: v1.21.0

$ kubectl version
Client Version: v1.32.1
Kustomize Version: v5.5.0
Server Version: v1.31.2
</pre>

**Kubernetes platform (e.g. Google Kubernetes Engine)**: Kind one node cluster

**Describe the bug**
I wanted to create a function (from container) and a route so you can access it using fission spec.
Applying the spec works as expected and the applications behaves as expected.
But using fission validate throws an error. I suppose this is an error because I assume that the config can't be incorrect and working as expected in the cluster
<pre>
$ fission spec validate
DeployUID: 5e1907dd-60b3-49eb-ae9a-0f5ad87660b3
Resources:
 * 1 Functions
 * 0 Environments
 * 0 Packages 
 * 1 Http Triggers 
 * 0 MessageQueue Triggers
 * 0 Time Triggers
 * 0 Kube Watchers
 * 0 ArchiveUploadSpec

Options:
  --specdir=''             Directory to store specs, defaults to ./specs
  --specignore=''          File containing specs to be ignored inside --specdir, defaults to .specignore
  --allowconflicts=false   If true, spec apply will be forced even if conflicting resources exist

Global Options:
  --verbosity=1 (-v)   CLI verbosity (0 is quiet, 1 is the default, 2 is verbose)
  --kube-context=''    Kubernetes context to be used for the execution of Fission commands
  --namespace='' (-n)  If present, the namespace scope for this CLI request

Usage:
  fission spec validate [options]

Error: error validating specs: 1 errors occurred:
        * MyHome/container_as_function_test/specs/route-http-echo.yaml:1: HTTPTrigger 'http-echo-route' references unknown function 'http-echo'
</pre>

**To Reproduce**
I have these files in the spec folder

*function-http-echo.yaml*
``` yaml
apiVersion: fission.io/v1
kind: Function
metadata:
  creationTimestamp: null
  name: http-echo
  namespace: default
spec:
  InvokeStrategy:
    ExecutionStrategy:
      ExecutorType: container
      MaxScale: 1
      MinScale: 0
      SpecializationTimeout: 120
      TargetCPUPercent: 0
    StrategyType: execution
  environment:
    name: ""
    namespace: ""
  functionTimeout: 60
  idletimeout: 120
  package:
    packageref:
      name: ""
      namespace: ""
  podspec:
    containers:
    - image: mendhak/http-https-echo
      name: http-echo
      ports:
      - containerPort: 8080
        name: http-env
      resources: {}
    imagePullSecrets:
    - {}
    terminationGracePeriodSeconds: 0
  resources: {}

```

*route-http-echo.yaml*
```yaml
apiVersion: fission.io/v1
kind: HTTPTrigger
metadata:
  creationTimestamp: null
  name: http-echo-route
spec:
  createingress: false
  functionref:
    functionweights: null
    name: http-echo
    type: name
  host: ""
  ingressconfig:
    annotations: null
    host: '*'
    path: /http-echo
    tls: ""
  method: ""
  methods:
  - GET
  - POST
  - PUT
  - DELETE
  prefix: /http-echo
  relativeurl: ""
```

*fission-deployment-config.yaml*
```yaml
# This file is generated by the 'fission spec init' command.
# See the README in this directory for background and usage information.
# Do not edit the UID below: that will break 'fission spec apply'
apiVersion: fission.io/v1
kind: DeploymentConfig
name: container-as-function-test
uid: 5e1907dd-60b3-49eb-ae9a-0f5ad87660b3
```

Running ```fission spec validate``` with these files present (no other files in directory other than readme)


**Expected result**
<!--A clear and concise description of what you expected to happen.-->
I would have expected the validate command to not throw an error.
**Actual result**
See the output above fission spec validate results above




Discussion / hints:
@GilbertBckr  
- Fission CLI generates the yaml and for `default` namespace, namespace under metadata is not mentioned.
- It seems that yaml file was modified manually and namespace was added to function yaml file.

Please try removing the `metadata.namespace` field from `function-http-echo.yaml` or regenerate the function yaml and try `fission spec validate`.
```
apiVersion: fission.io/v1
kind: Function
metadata:
  creationTimestamp: null
  name: http-echo
spec:
  InvokeStrategy:
    ExecutionStrategy:
      ExecutorType: container
      MaxScale: 1
      MinScale: 0
      SpecializationTimeout: 120
      TargetCPUPercent: 0
    StrategyType: execution
  environment:
    name: ""
    namespace: ""
  functionTimeout: 60
  idletimeout: 120
  package:
    packageref:
      name: ""
      namespace: ""
  podspec:
    containers:
    - image: mendhak/http-https-echo
      name: http-echo
      ports:
      - containerPort: 8080
        name: http-env
      resources: {}
    imagePullSecrets:
    - {}
    terminationGracePeriodSeconds: 0
  resources: {}

```
Please let us know if it resolves your issue.


- If validation itself failed then `fission spec apply` should have also failed, we will investigate this further and update here.

Thanks for raising the issue.
@soharab-ic 
Thank you so much for the quick reply. I must have forgotten I added that field. It works now, thank you very much!

Fix patch:
diff --git a/pkg/fission-cli/cmd/spec/apply.go b/pkg/fission-cli/cmd/spec/apply.go
index b999f8bf3f..164735ed8d 100644
--- a/pkg/fission-cli/cmd/spec/apply.go
+++ b/pkg/fission-cli/cmd/spec/apply.go
@@ -177,11 +177,6 @@ func (opts *ApplySubCommand) run(input cli.Input) error {
 			return errors.Wrap(err, "error reading specs")
 		}
 
-		err = opts.insertNamespace(input, fr)
-		if err != nil {
-			return errors.Wrap(err, "error reading specs")
-		}
-
 		if validateSpecs {
 			err = validateForApply(input, fr)
 			if err != nil {
@@ -189,6 +184,11 @@ func (opts *ApplySubCommand) run(input cli.Input) error {
 			}
 		}
 
+		err = opts.insertNamespace(input, fr)
+		if err != nil {
+			return errors.Wrap(err, "error inserting namespace")
+		}
+
 		err = warnIfDirtyWorkTree(filepath.Clean(specDir + "/.."))
 		if err != nil {
 			console.Warn(err.Error())


Test patch: