@@ -31,6 +31,8 @@ import (
31
31
"github.com/layer5io/meshery-linkerd/pkg/util"
32
32
"github.com/pkg/errors"
33
33
"github.com/sirupsen/logrus"
34
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
35
+ corev1 "k8s.io/api/core/v1"
34
36
)
35
37
36
38
const (
@@ -64,10 +66,42 @@ type Release struct {
64
66
Assets []* Asset `json:"assets,omitempty"`
65
67
}
66
68
69
+ // AddAnnotation is used to mark namespaces for automatic sidecar injection (or not)
70
+ func (iClient * Client ) AddAnnotation (namespace string , remove bool ) error {
71
+ ns , err := iClient .k8sClientset .CoreV1 ().Namespaces ().Get (namespace , metav1.GetOptions {})
72
+ if err != nil {
73
+ _ ,err := iClient .k8sClientset .CoreV1 ().Namespaces ().Create (& corev1.Namespace {
74
+ ObjectMeta : metav1.ObjectMeta {
75
+ Name : namespace ,
76
+ }})
77
+ if err != nil {
78
+ err = errors .Wrapf (err , "Unable to create namespace" )
79
+ return err
80
+ }
81
+ }
82
+
83
+ if ns .ObjectMeta .Annotations == nil {
84
+ ns .ObjectMeta .Annotations = map [string ]string {}
85
+ }
86
+ ns .ObjectMeta .Annotations ["linkerd.io/inject" ] = "enabled"
87
+
88
+ if remove {
89
+ delete (ns .ObjectMeta .Annotations , "linkerd.io/inject" );
90
+ }
91
+
92
+ _ , err = iClient .k8sClientset .CoreV1 ().Namespaces ().Update (ns )
93
+ if err != nil {
94
+ err = errors .Wrapf (err , "Unable to update namespace with annotation" )
95
+ return err
96
+ }
97
+ return nil
98
+ }
99
+
100
+ // getLatestRelease is to pull down the Linkerd packages
67
101
func (iClient * Client ) getLatestReleaseURL () error {
68
102
69
103
if iClient .linkerdReleaseDownloadURL == "" || time .Since (iClient .linkerdReleaseUpdatedAt ) > cachePeriod {
70
- logrus .Debugf ("API info url: %s" , repoURL )
104
+ logrus .Debugf ("API info url: %s " , repoURL )
71
105
resp , err := http .Get (repoURL )
72
106
if err != nil {
73
107
err = errors .Wrapf (err , "error getting latest version info" )
@@ -118,6 +152,7 @@ func (iClient *Client) getLatestReleaseURL() error {
118
152
return nil
119
153
}
120
154
155
+ // downloadFile pulls the release packages
121
156
func (iClient * Client ) downloadFile (urlToDownload , localFile string ) error {
122
157
dFile , err := os .Create (localFile )
123
158
if err != nil {
@@ -159,6 +194,7 @@ func (iClient *Client) downloadFile(urlToDownload, localFile string) error {
159
194
return nil
160
195
}
161
196
197
+ // downloadLinkerd pull down packages
162
198
func (iClient * Client ) downloadLinkerd () error {
163
199
logrus .Debug ("preparing to download the latest linkerd release" )
164
200
err := iClient .getLatestReleaseURL ()
@@ -189,6 +225,7 @@ func (iClient *Client) downloadLinkerd() error {
189
225
return nil
190
226
}
191
227
228
+ // execute processes the command given to it
192
229
func (iClient * Client ) execute (command ... string ) (string , string , error ) {
193
230
err := iClient .downloadLinkerd ()
194
231
if err != nil {
@@ -219,6 +256,7 @@ func (iClient *Client) execute(command ...string) (string, string, error) {
219
256
return outb .String (), errb .String (), nil
220
257
}
221
258
259
+ // getYAML retrieves remote yaml file
222
260
func (iClient * Client ) getYAML (remoteURL , localFile string ) (string , error ) {
223
261
224
262
proceedWithDownload := true
0 commit comments