-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Meshync Dynamic Configuration from Meshsync #258
Changes from 4 commits
63ab2a3
8fecc42
c2f557e
80d8263
439496a
2ee712f
543b383
55d3cc3
3dcd825
042eb80
46256a9
c82b97c
4837992
95c9d15
0e99363
d1b0c76
a01a14a
6d68702
be975d8
077384f
99d89b2
89d41ad
988de5b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package config | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
|
||
"github.com/layer5io/meshkit/utils" | ||
mesherykube "github.com/layer5io/meshkit/utils/kubernetes" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
) | ||
|
||
var ( | ||
namespace = "meshery" // Namespace for the Custom Resource | ||
crName = "meshery-meshsync" // Name of the custom resource | ||
version = "v1alpha1" // Version of the Custom Resource | ||
group = "meshery.layer5.io" //Group for the Custom Resource | ||
resource = "meshsyncs" //Name of the Resource | ||
) | ||
|
||
func GetMeshsyncCRDConfigs() (*MeshsyncConfig, error) { | ||
// Initialize kubeclient | ||
kubeClient, err := mesherykube.New(nil) | ||
if err != nil { | ||
return nil, ErrInitConfig(err) | ||
} | ||
// initialize the dynamic kube client | ||
dyClient := kubeClient.DynamicKubeClient | ||
|
||
// initialize the group version resource to access the custom resource | ||
gvr := schema.GroupVersionResource{Version: version, Group: group, Resource: resource} | ||
|
||
// make a call to get the custom resource | ||
crd, err := dyClient.Resource(gvr).Namespace(namespace).Get(context.TODO(), crName, metav1.GetOptions{}) | ||
|
||
if err != nil { | ||
return nil, ErrInitConfig(err) | ||
} | ||
// get the spec section of the unstructured object | ||
KiptoonKipkurui marked this conversation as resolved.
Show resolved
Hide resolved
|
||
spec := crd.Object["spec"] | ||
configObj := spec.(map[string]interface{})["config"] | ||
|
||
KiptoonKipkurui marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if configObj == nil { | ||
return nil, ErrInitConfig(errors.New("Custom Resource does not have Meshsync Configs")) | ||
} | ||
configStr, err := utils.Marshal(configObj) | ||
if err != nil { | ||
return nil, ErrInitConfig(err) | ||
} | ||
meshsyncConfig := MeshsyncConfig{} | ||
err = utils.Unmarshal(string(configStr), &meshsyncConfig) | ||
|
||
if err != nil { | ||
return nil, ErrInitConfig(err) | ||
} | ||
return &meshsyncConfig, nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,20 @@ func main() { | |
os.Exit(1) | ||
} | ||
|
||
// get configs from meshsync crd if available | ||
crdConfigs, err := config.GetMeshsyncCRDConfigs() | ||
|
||
if err != nil { | ||
// no configs found from meshsync CRD log warning | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure the log level should be warning level, please get confirm from @leecalcote @theBeginner86. I assume that if we cannot get configs, it should be the Info level? Because we have the default configuraiton. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The choice of using a warning log is because the desired state of configuration for Meshsync from now and in future lies is utilizing the crd as per conversations with @leecalcote and @theBeginner86 so this is an extra speed bump to notify one that the desired approach has not been utilized |
||
log.Warn(err) | ||
} | ||
|
||
// pass configs from crd to default configs | ||
if crdConfigs != nil { | ||
config.Pipelines = crdConfigs.PipelineConfigs | ||
config.Listeners = crdConfigs.ListenerConfigs | ||
} | ||
|
||
// Config init and seed | ||
cfg, err := config.New(provider) | ||
if err != nil { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you can import it rather than hard coded it https://github.com/meshery/meshery-operator/blob/master/api/v1alpha1/meshsync_types.go. Same like
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will update meshsync with this change immediately the meshery operator is approved with the CRD changes