Skip to content

Commit b16b932

Browse files
authored
Merge pull request #157 from utkarsh-pro/utkarsh-pro/feature/customoperations
add feature to apply custom operation
2 parents 6c51a68 + dcb432e commit b16b932

File tree

3 files changed

+44
-9
lines changed

3 files changed

+44
-9
lines changed

linkerd/custom_operation.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package linkerd
2+
3+
import (
4+
"github.com/layer5io/meshery-adapter-library/status"
5+
)
6+
7+
func (linkerd *Linkerd) applyCustomOperation(namespace string, manifest string, isDel bool) (string, error) {
8+
st := status.Starting
9+
10+
err := linkerd.applyManifest([]byte(manifest), isDel, namespace)
11+
if err != nil {
12+
return st, ErrCustomOperation(err)
13+
}
14+
15+
return status.Completed, nil
16+
}

linkerd/error.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@ import (
77
)
88

99
var (
10-
ErrInstallLinkerdCode = "linkerd_test_code"
11-
ErrMeshConfigCode = "linkerd_test_code"
12-
ErrFetchManifestCode = "linkerd_test_code"
13-
ErrDownloadBinaryCode = "linkerd_test_code"
14-
ErrInstallBinaryCode = "linkerd_test_code"
15-
ErrClientConfigCode = "linkerd_test_code"
16-
ErrClientSetCode = "linkerd_test_code"
17-
ErrStreamEventCode = "linkerd_test_code"
18-
ErrSampleAppCode = "linkerd_test_code"
10+
ErrInstallLinkerdCode = "linkerd_test_code"
11+
ErrMeshConfigCode = "linkerd_test_code"
12+
ErrFetchManifestCode = "linkerd_test_code"
13+
ErrDownloadBinaryCode = "linkerd_test_code"
14+
ErrInstallBinaryCode = "linkerd_test_code"
15+
ErrClientConfigCode = "linkerd_test_code"
16+
ErrClientSetCode = "linkerd_test_code"
17+
ErrStreamEventCode = "linkerd_test_code"
18+
ErrSampleAppCode = "linkerd_test_code"
19+
ErrCustomOperationCode = "linkerd_test_code"
1920

2021
ErrOpInvalid = errors.NewDefault(errors.ErrOpInvalid, "Invalid operation")
2122
)
@@ -64,3 +65,8 @@ func ErrStreamEvent(err error) error {
6465
func ErrSampleApp(err error) error {
6566
return errors.NewDefault(ErrSampleAppCode, fmt.Sprintf("Error with sample app operation: %s", err.Error()))
6667
}
68+
69+
// ErrCustomOperation is the error for streaming event
70+
func ErrCustomOperation(err error) error {
71+
return errors.NewDefault(ErrCustomOperationCode, fmt.Sprintf("Error with custom operation: %s", err.Error()))
72+
}

linkerd/linkerd.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,19 @@ func (linkerd *Linkerd) ApplyOperation(ctx context.Context, opReq adapter.Operat
8787
ee.Details = ""
8888
hh.StreamInfo(e)
8989
}(linkerd, e)
90+
case common.CustomOperation:
91+
go func(hh *Linkerd, ee *adapter.Event) {
92+
stat, err := hh.applyCustomOperation(opReq.Namespace, opReq.CustomBody, opReq.IsDeleteOperation)
93+
if err != nil {
94+
e.Summary = fmt.Sprintf("Error while %s custom operation", stat)
95+
e.Details = err.Error()
96+
hh.StreamErr(e, err)
97+
return
98+
}
99+
ee.Summary = fmt.Sprintf("custom operation %s successfully", stat)
100+
ee.Details = fmt.Sprintf("Custom operation %s successfully", stat)
101+
hh.StreamInfo(e)
102+
}(linkerd, e)
90103
default:
91104
linkerd.StreamErr(e, ErrOpInvalid)
92105
}

0 commit comments

Comments
 (0)