[Feature] [Operator] Optimize the InjectStorage method of OAPServerReconciler to improve the efficiency of Reconcile execution
Maintainers usually reply within 1 day
@dashanji is already working on this.
Since Nov 13, 2023.
Assessment
This issue has not been assessed yet.
Description
Search before asking
- I had searched in the issues and found no similar feature requirement.
Description
the skywalking-swck version is v0.8.0. when i create an oapserver instance, the OAPServerReconciler will excute reconcile method, I found the InjectStorage method is only used to check storage name and get storage info like SW_STORAGE_ES_HTTP_PROTOCOL,SW_STORAGE, SW_ES_USER, SW_ES_PASSWORD and so on to append to oapserver.spec.config field. But this method and subsequent methods does not perform update the oapserver instance to kube-apiserver. So these updates are invalid, can we optimize the InjectStorage method to only check whether the storage name is exists?
func (r *OAPServerReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
log := runtimelog.FromContext(ctx)
log.Info("=====================oapserver reconcile started================================")
oapServer := operatorv1alpha1.OAPServer{}
if err := r.Client.Get(ctx, req.NamespacedName, &oapServer); err != nil {
return ctrl.Result{}, client.IgnoreNotFound(err)
}
ff, err := r.FileRepo.GetFilesRecursive("templates")
if err != nil {
log.Error(err, "failed to load resource templates")
return ctrl.Result{}, err
}
app := kubernetes.Application{
Client: r.Client,
FileRepo: r.FileRepo,
CR: &oapServer,
GVK: operatorv1alpha1.GroupVersion.WithKind("OAPServer"),
Recorder: r.Recorder,
}
r.InjectStorage(ctx, log, &oapServer)
if err := app.ApplyAll(ctx, ff, log); err != nil {
return ctrl.Result{}, err
}
if err := r.checkState(ctx, log, &oapServer); err != nil {
l.Error(err, "failed to check sub resources state")
return ctrl.Result{}, err
}
return ctrl.Result{RequeueAfter: schedDuration}, nil
}
// InjectStorage Inject Storage
func (r *OAPServerReconciler) InjectStorage(ctx context.Context, log logr.Logger, oapServer *operatorv1alpha1.OAPServer) {
if oapServer.Spec.StorageConfig.Name == "" {
return
}
storage := &operatorv1alpha1.Storage{}
err := r.Client.Get(ctx, client.ObjectKey{Namespace: oapServer.Namespace, Name: oapServer.Spec.StorageConfig.Name}, storage)
if err == nil {
r.ConfigStorage(ctx, log, storage, oapServer)
log.Info("success inject storage")
} else {
log.Info("fail inject storage")
}
}
func (r *OAPServerReconciler) ConfigStorage(ctx context.Context, log logr.Logger, s *operatorv1alpha1.Storage, o *operatorv1alpha1.OAPServer) {
user, tls := s.Spec.Security.User, s.Spec.Security.TLS
SwStorageEsHTTPProtocol := "http"
SwEsUser := ""
SwEsPassword := ""
SwStorageEsSslJksPath := ""
SwStorageEsSslJksPass := "skywalking"
SwStorageEsClusterNodes := ""
o.Spec.StorageConfig.Storage = *s
if user.SecretName != "" {
if user.SecretName == "default" {
SwEsUser = "elastic"
SwEsPassword = "changeme"
} else {
usersecret := &core.Secret{}
if err := r.Client.Get(ctx, client.ObjectKey{Namespace: s.Namespace, Name: user.SecretName}, usersecret); err != nil && !apierrors.IsNotFound(err) {
log.Info("fail get usersecret ")
}
for k, v := range usersecret.Data {
if k == "username" {
SwEsUser = string(v)
} else if k == "password" {
SwEsPassword = string(v)
}
}
}
}
if tls {
SwStorageEsHTTPProtocol = "https"
SwStorageEsSslJksPath = "/skywalking/p12/storage.p12"
SwStorageEsClusterNodes = "skywalking-storage"
} else {
SwStorageEsClusterNodes = s.Name + "-" + s.Spec.Type
}
o.Spec.Config = append(o.Spec.Config, core.EnvVar{Name: "SW_STORAGE", Value: s.Spec.Type})
if user.SecretName != "" {
o.Spec.Config = append(o.Spec.Config, core.EnvVar{Name: "SW_ES_USER", Value: SwEsUser})
o.Spec.Config = append(o.Spec.Config, core.EnvVar{Name: "SW_ES_PASSWORD", Value: SwEsPassword})
}
if tls {
o.Spec.Config = append(o.Spec.Config, core.EnvVar{Name: "SW_STORAGE_ES_SSL_JKS_PATH", Value: SwStorageEsSslJksPath})
o.Spec.Config = append(o.Spec.Config, core.EnvVar{Name: "SW_STORAGE_ES_SSL_JKS_PASS", Value: SwStorageEsSslJksPass})
}
if apiequal.Semantic.DeepDerivative(s.Spec.ConnectType, "external") {
parseurl, _ := url.Parse(s.Spec.ConnectAddress)
SwStorageEsHTTPProtocol = parseurl.Scheme
SwStorageEsClusterNodes = parseurl.Host
o.Spec.Config = append(o.Spec.Config, core.EnvVar{Name: "SW_STORAGE_ES_HTTP_PROTOCOL", Value: SwStorageEsHTTPProtocol})
o.Spec.Config = append(o.Spec.Config, core.EnvVar{Name: "SW_STORAGE_ES_CLUSTER_NODES", Value: SwStorageEsClusterNodes})
} else {
o.Spec.Config = append(o.Spec.Config, core.EnvVar{Name: "SW_STORAGE_ES_HTTP_PROTOCOL", Value: SwStorageEsHTTPProtocol})
o.Spec.Config = append(o.Spec.Config, core.EnvVar{Name: "SW_STORAGE_ES_CLUSTER_NODES", Value: SwStorageEsClusterNodes + ":9200"})
}
}
Use case
No response
Related issues
No response
Are you willing to submit a pull request to implement this on your own?
- Yes I am willing to submit a pull request on my own!
Code of Conduct
- I agree to follow this project's Code of Conduct
- Dominant language
- Java
- Stars
- 25k
- Forks
- 6.6k
- Avg merge
- 12h 1m
- Merged PRs (30d)
- 43
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from apache/skywalking
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
apache/skywalking#14239 ·
Maintainers usually reply within 1 day
-
AI Assistant database enhancement
Difficulty 5/5 Over a week Newbie friendliness 24/100
apache/skywalking#14237 ·
Maintainers usually reply within 1 day
-
database enhancement
Difficulty 5/5 Over a week Newbie friendliness 25/100
apache/skywalking#14236 ·
Maintainers usually reply within 1 day
-
AI Assistant database enhancement
Difficulty 5/5 Over a week Newbie friendliness 25/100
apache/skywalking#14235 ·
Maintainers usually reply within 1 day
-
database enhancement
Difficulty 5/5 Over a week Newbie friendliness 30/100
apache/skywalking#14234 ·
Maintainers usually reply within 1 day
All issues in apache/skywalking
Similar issues
-
Re-executed query with IN condition on an index column returns deleted rows (stale IndexCursor)Possibly taken @dbusche claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
h2database/h2database#4580 ·
Maintainers usually reply within 1 day
-
vips-drift
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Stirling-Tools/JPDFium#300 ·
Maintainers usually reply within 1 day
-
hermes-queue
Difficulty 1/5 1-3 hours Newbie friendliness 85/100
chrisalunlloyd2-sudo/mindpalace#403 ·
Maintainers usually reply within 1 day
-
Guidelines: document how to build a use case against a local, unpublished Flow/browserless-test changePossibly taken @totally-not-ai claimed this today. Open
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
vaadin/use-cases#452 · 1 comment ·
Maintainers usually reply within 1 day
-
area/storage area/storage/sql
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Apicurio/apicurio-registry#11159 ·
Maintainers usually reply within 1 day