-
Notifications
You must be signed in to change notification settings - Fork 1
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
add serviceexport and resourceexport controllers #22
Conversation
SourceServiceType = "SourceServiceType" | ||
) | ||
|
||
var LeaderNameSpace string |
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.
var LeaderNameSpace string | |
var LeaderNamespace string |
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.
done
Scheme *runtime.Scheme | ||
K8sClient kubernetes.Interface | ||
LeaderK8sClient kubernetes.Interface | ||
K8smcsCrdClient k8smcsversioned.Interface |
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.
K8smcsCrdClient k8smcsversioned.Interface | |
K8sMcsCrdClient k8smcsversioned.Interface |
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.
done
|
||
func svcInfoKeyFunc(obj interface{}) (string, error) { | ||
svc := obj.(*svcInfo) | ||
return svc.namespace + svc.name, 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 we can use the NamespacedName func to return such keys
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.
done, add a func NamespacedName in helper.go and call it here.
|
||
func epInfoKeyFunc(obj interface{}) (string, error) { | ||
ep := obj.(*epInfo) | ||
return ep.namespace + ep.name, 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.
ditto
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.
done
return ep.namespace + ep.name, nil | ||
} | ||
|
||
func epIndexerByLabelFunc(obj interface{}) ([]string, error) { |
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.
should the labels be normalized in a string to make sure it always returns a predictable string
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.
done, sort the key first, then append them as a string.
} | ||
clusterID := LocalClusterID | ||
|
||
key := req.Namespace + req.Name |
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.
here too you could use the namespacedName func
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.
done
//+kubebuilder:rbac:groups="",resources=services,verbs=get;list;watch;update | ||
//+kubebuilder:rbac:groups="",resources=endpoints,verbs=get;list;watch;update | ||
//+kubebuilder:rbac:groups="",resources=nodes,verbs=get;list;watch | ||
|
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.
general comment for the package: maybe add docstrings for each func and methods to explain what is being done.. more comments in the code .. the better
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.
done
70dd255
to
b26e418
Compare
09e1f30
to
ef751b5
Compare
1. add serviceexport_controller, for each ServiceExport CR, it will have two ResourceExports in leader cluster, one kind is Service, another one is Endpoints, the name format is <clusterid>-<namespace>-<servicename>-<kind>. 2. resourceexport_controller will watch resourceexport event and extract service/endpoints from resourceexport and wrapp them from member clusters into one ResourceImport if source service's Namespace and Name are the same 3. disable auth proxy since we didn't add manager_auth_proxy_patch.yaml in default kustomization.yaml 4. regenerate multi-cluster.yaml Signed-off-by: Lan Luo <luola@vmware.com>
} | ||
|
||
resImportName := getResourceImportName(&existRe) | ||
if len(reList.Items) == 0 { |
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 know what we are doing here .. but would be good to add comments for someone not aware of why we need to check the resExport list before cleaning up the relevant resImp
if existRe.Spec.Kind == ServiceKind { | ||
return ctrl.Result{}, nil | ||
} | ||
uniqueIndex := existRe.Spec.Namespace + existRe.Spec.Name + existRe.Spec.ClusterID + EndpointsKind |
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.
this sounds like could be a func too..
_ = log.FromContext(ctx) | ||
klog.V(2).Infof("reconcile for %s", req.NamespacedName) | ||
var resExport mcsv1alpha1.ResourceExport | ||
if err := r.Client.Get(ctx, req.NamespacedName, &resExport); 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.
could we break up the Reconcile func to deleteResExport() add/updateResExport() ? to make it easier to read
for eg following block of code is for delete event ..
klog.Infof("local ClusterID is %s", clusterID) | ||
|
||
var svcExport k8smcsv1alpha1.ServiceExport | ||
key := NamespacedName(req.Namespace, req.Name) |
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 noticed req has NamespacedName
some of these were old comments.. merging it and we can follow up on TODOs |
ResourceExports in leader cluster, one kind is Service, another one is Endpoints,
the name format is ---.
and extract service/endpoints from resourceexport and wrapp
them from member clusters into one ResourceImport if source service's
Namespace and Name are the same
Signed-off-by: Lan Luo luola@vmware.com