Skip to content
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

fix: remove the explicit use of pingcap/log #3674

Merged
merged 4 commits into from
Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions controllers/chaosimpl/jvmchaos/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ import (

"github.com/go-logr/logr"
"github.com/pingcap/errors"
"github.com/pingcap/log"
"go.uber.org/fx"
"go.uber.org/zap"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/chaos-mesh/chaos-mesh/api/v1alpha1"
Expand Down Expand Up @@ -130,6 +128,8 @@ func (impl *Impl) Apply(ctx context.Context, index int, records []*v1alpha1.Reco
jvmChaos := obj.(*v1alpha1.JVMChaos)
err = generateRuleData(&jvmChaos.Spec)
if err != nil {
impl.Log.Error(err, "fail to generate rule data")

return v1alpha1.Injected, err
}

Expand Down Expand Up @@ -173,6 +173,8 @@ func (impl *Impl) Recover(ctx context.Context, index int, records []*v1alpha1.Re
jvmChaos := obj.(*v1alpha1.JVMChaos)
err = generateRuleData(&jvmChaos.Spec)
if err != nil {
impl.Log.Error(err, "fail to generate rule data")

return v1alpha1.Injected, err
}

Expand Down Expand Up @@ -286,7 +288,6 @@ func generateRuleData(spec *v1alpha1.JVMChaosSpec) error {
}
err := t.Execute(buf, bytemanTemplateSpec)
if err != nil {
log.Error("executing template", zap.Error(err))
return err
}

Expand All @@ -295,7 +296,7 @@ func generateRuleData(spec *v1alpha1.JVMChaosSpec) error {
}

// Object would return the instance of chaos
func NewImpl(c client.Client, log logr.Logger, decoder *utils.ContainerRecordDecoder) *impltypes.ChaosImplPair {
func NewImpl(c client.Client, decoder *utils.ContainerRecordDecoder, log logr.Logger) *impltypes.ChaosImplPair {
return &impltypes.ChaosImplPair{
Name: "jvmchaos",
Object: &v1alpha1.JVMChaos{},
Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ require (
github.com/onsi/gomega v1.17.0
github.com/pingcap/errors v0.11.5-0.20190809092503-95897b64e011
github.com/pingcap/failpoint v0.0.0-20200210140405-f8f9fb234798
github.com/pingcap/log v0.0.0-20200117041106-d28c14d3b1cd
github.com/pkg/errors v0.9.1
github.com/pkg/sftp v1.13.4
github.com/prometheus/client_golang v1.12.1
Expand Down Expand Up @@ -231,7 +230,6 @@ require (
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20220107163113-42d7afdf6368 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
3 changes: 1 addition & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1039,9 +1039,8 @@ github.com/pingcap/errors v0.11.5-0.20190809092503-95897b64e011 h1:58naV4XMEqm0h
github.com/pingcap/errors v0.11.5-0.20190809092503-95897b64e011/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8=
github.com/pingcap/failpoint v0.0.0-20200210140405-f8f9fb234798 h1:6DMbRqPI1qzQ8N1xc3+nKY8IxSACd9VqQKkRVvbyoIg=
github.com/pingcap/failpoint v0.0.0-20200210140405-f8f9fb234798/go.mod h1:DNS3Qg7bEDhU6EXNHF+XSv/PGznQaMJ5FWvctpm6pQI=
github.com/pingcap/log v0.0.0-20191012051959-b742a5d432e9 h1:AJD9pZYm72vMgPcQDww9rkZ1DnWfl0pXV3BOWlkYIjA=
github.com/pingcap/log v0.0.0-20191012051959-b742a5d432e9/go.mod h1:4rbK1p9ILyIfb6hU7OG2CiWSqMXnp3JMbiaVJ6mvoY8=
github.com/pingcap/log v0.0.0-20200117041106-d28c14d3b1cd h1:CV3VsP3Z02MVtdpTMfEgRJ4T9NGgGTxdHpJerent7rM=
github.com/pingcap/log v0.0.0-20200117041106-d28c14d3b1cd/go.mod h1:4rbK1p9ILyIfb6hU7OG2CiWSqMXnp3JMbiaVJ6mvoY8=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1-0.20171018195549-f15c970de5b7/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down
31 changes: 13 additions & 18 deletions pkg/chaosdaemon/jvm_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ import (
"strings"

"github.com/golang/protobuf/ptypes/empty"
"github.com/pingcap/log"
"github.com/pkg/errors"
"go.uber.org/zap"

"github.com/chaos-mesh/chaos-mesh/pkg/bpm"
pb "github.com/chaos-mesh/chaos-mesh/pkg/chaosdaemon/pb"
Expand Down Expand Up @@ -69,7 +67,7 @@ func (s *DaemonServer) InstallJVMRules(ctx context.Context,
return nil, errors.New("environment variable BYTEMAN_HOME not set")
}

// copy byteman.jar and byteman-helper.jar to container's namespace
// Copy byteman.jar, byteman-helper.jar and chaos-agent.jar into container's namespace.
if req.EnterNS {
processBuilder := bpm.DefaultProcessBuilder("sh", "-c", fmt.Sprintf("mkdir -p %s/lib/", bytemanHome)).SetContext(ctx).SetNS(pid, bpm.MountNS)
output, err := processBuilder.Build(ctx).CombinedOutput()
Expand All @@ -80,18 +78,18 @@ func (s *DaemonServer) InstallJVMRules(ctx context.Context,
log.Info("mkdir", "output", string(output))
}

err = copyFileAcrossNS(ctx, fmt.Sprintf("%s/lib/byteman.jar", bytemanHome), "/usr/local/byteman/lib/byteman.jar", pid)
if err != nil {
return nil, err
}
jars := []string{"byteman.jar", "byteman-helper.jar", "chaos-agent.jar"}

err = copyFileAcrossNS(ctx, fmt.Sprintf("%s/lib/byteman-helper.jar", bytemanHome), "/usr/local/byteman/lib/byteman-helper.jar", pid)
if err != nil {
return nil, err
}
err = copyFileAcrossNS(ctx, fmt.Sprintf("%s/lib/chaos-agent.jar", bytemanHome), "/usr/local/byteman/lib/chaos-agent.jar", pid)
if err != nil {
return nil, err
for _, jar := range jars {
source := fmt.Sprintf("%s/lib/%s", bytemanHome, jar)
dest := fmt.Sprintf("/usr/local/byteman/lib/%s", jar)

err = copyFileAcrossNS(ctx, source, dest, pid)
if err != nil {
return nil, err
}

log.Info("copy", jar, "from source:", source, "to destination:", dest)
}
}

Expand Down Expand Up @@ -225,13 +223,10 @@ func copyFileAcrossNS(ctx context.Context, source string, dest string, pid uint3

processBuilder := bpm.DefaultProcessBuilder("sh", "-c", fmt.Sprintf("cat > %s", dest)).SetContext(ctx)
processBuilder = processBuilder.SetNS(pid, bpm.MountNS).SetStdin(sourceFile)
output, err := processBuilder.Build(ctx).CombinedOutput()
_, err = processBuilder.Build(ctx).CombinedOutput()
if err != nil {
return err
}
if len(output) > 0 {
log.Info("copy file", zap.String("source", source), zap.String("destination", dest), zap.String("output", string(output)))
}

return nil
}