Skip to content

Commit 426052f

Browse files
committed
capi system: write etcd and kube-apiserver logs
Captures etcd and kube-apiserver logs to the cluster api artifacts directory.
1 parent 98c5d71 commit 426052f

File tree

4 files changed

+33
-9
lines changed

4 files changed

+33
-9
lines changed

cmd/openshift-install/gather.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ import (
2424
"github.com/openshift/installer/pkg/asset/installconfig"
2525
assetstore "github.com/openshift/installer/pkg/asset/store"
2626
"github.com/openshift/installer/pkg/asset/tls"
27+
"github.com/openshift/installer/pkg/clusterapi"
2728
serialgather "github.com/openshift/installer/pkg/gather"
2829
"github.com/openshift/installer/pkg/gather/service"
2930
"github.com/openshift/installer/pkg/gather/ssh"
3031
"github.com/openshift/installer/pkg/infrastructure"
31-
"github.com/openshift/installer/pkg/infrastructure/clusterapi"
3232
infra "github.com/openshift/installer/pkg/infrastructure/platform"
3333

3434
_ "github.com/openshift/installer/pkg/gather/aws"
@@ -254,7 +254,7 @@ func gatherCAPIManifests(directory, gatherID string) (string, error) {
254254
return "", fmt.Errorf("failed to get absolute path for %s: %w", directory, err)
255255
}
256256

257-
capiDir := filepath.Join(dir, clusterapi.CAPIArtifactsDir)
257+
capiDir := filepath.Join(dir, clusterapi.ArtifactsDir)
258258
if _, err := os.Stat(capiDir); err != nil {
259259
if errors.Is(err, fs.ErrNotExist) {
260260
return "", fmt.Errorf("either Cluster API manifests not generated or terraform provision")

pkg/clusterapi/localcontrolplane.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ type localControlPlane struct {
5555
Cfg *rest.Config
5656
BinDir string
5757
KubeconfigPath string
58+
EtcdLog *os.File
59+
APIServerLog *os.File
5860
}
5961

6062
// Run launches the local control plane.
@@ -68,21 +70,38 @@ func (c *localControlPlane) Run(ctx context.Context) error {
6870
return fmt.Errorf("failed to unpack envtest binaries: %w", err)
6971
}
7072

73+
// Write etcd & kube-apiserver output to log files.
74+
var err error
75+
if err := os.MkdirAll(filepath.Join(command.RootOpts.Dir, ArtifactsDir), 0750); err != nil {
76+
return fmt.Errorf("error creating artifacts dir: %w", err)
77+
}
78+
if c.EtcdLog, err = os.Create(filepath.Join(command.RootOpts.Dir, ArtifactsDir, "etcd.log")); err != nil {
79+
return fmt.Errorf("failed to create etcd log file: %w", err)
80+
}
81+
if c.APIServerLog, err = os.Create(filepath.Join(command.RootOpts.Dir, ArtifactsDir, "kube-apiserver.log")); err != nil {
82+
return fmt.Errorf("failed to create kube-apiserver log file: %w", err)
83+
}
84+
7185
log.SetLogger(klog.NewKlogr())
7286
logrus.Info("Started local control plane with envtest")
7387
c.Env = &envtest.Environment{
7488
Scheme: Scheme,
75-
AttachControlPlaneOutput: false,
89+
AttachControlPlaneOutput: true,
7690
BinaryAssetsDirectory: c.BinDir,
7791
ControlPlaneStartTimeout: 10 * time.Second,
7892
ControlPlaneStopTimeout: 10 * time.Second,
7993
ControlPlane: envtest.ControlPlane{
8094
Etcd: &envtest.Etcd{
8195
DataDir: c.BinDir,
96+
Out: c.EtcdLog,
97+
Err: c.EtcdLog,
98+
},
99+
APIServer: &envtest.APIServer{
100+
Out: c.APIServerLog,
101+
Err: c.APIServerLog,
82102
},
83103
},
84104
}
85-
var err error
86105
c.Cfg, err = c.Env.Start()
87106
if err != nil {
88107
return err

pkg/clusterapi/system.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ const (
4747
SystemStateRunning SystemState = "running"
4848
// SystemStateStopped indicates the system is stopped.
4949
SystemStateStopped SystemState = "stopped"
50+
51+
// ArtifactsDir is the directory where output (manifests, kubeconfig, etc.)
52+
// related to CAPI-based installs are stored.
53+
ArtifactsDir = ".clusterapi_output"
5054
)
5155

5256
// Interface is the interface for the cluster-api system.
@@ -365,6 +369,10 @@ func (c *system) Teardown() {
365369
// Clean up the binary directory.
366370
defer os.RemoveAll(c.lcp.BinDir)
367371

372+
// Clean up log file handles.
373+
defer c.lcp.EtcdLog.Close()
374+
defer c.lcp.APIServerLog.Close()
375+
368376
// Proceed to shutdown.
369377
c.teardownOnce.Do(func() {
370378
c.cancel()

pkg/infrastructure/clusterapi/clusterapi.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ const (
5353
ignitionStage = "Bootstrap Ignition Provisioning"
5454
machineStage = "Machine Provisioning"
5555
postProvisionStage = "Infrastructure Post-provisioning"
56-
57-
// CAPIArtifactsDir is the directory where the manifests generated by CAPI are stored.
58-
CAPIArtifactsDir = ".clusterapi_output"
5956
)
6057

6158
// InfraProvider implements common Cluster API logic and
@@ -463,7 +460,7 @@ func extractIPAddress(manifestPath string) (string, error) {
463460

464461
// ExtractHostAddresses extracts the IPs of the bootstrap and control plane machines.
465462
func (i *InfraProvider) ExtractHostAddresses(dir string, config *types.InstallConfig, ha *infrastructure.HostAddresses) error {
466-
manifestsDir := filepath.Join(dir, CAPIArtifactsDir)
463+
manifestsDir := filepath.Join(dir, clusterapi.ArtifactsDir)
467464
logrus.Debugf("Looking for machine manifests in %s", manifestsDir)
468465

469466
bootstrapFiles, err := filepath.Glob(filepath.Join(manifestsDir, "Machine\\-openshift\\-cluster\\-api\\-guests\\-*\\-bootstrap.yaml"))
@@ -544,7 +541,7 @@ func (i *InfraProvider) collectManifests(ctx context.Context, cl client.Client)
544541
errorList = append(errorList, fmt.Errorf("failed to get GVK for manifest %s: %w", m.GetName(), err))
545542
continue
546543
}
547-
fileName := filepath.Join(CAPIArtifactsDir, fmt.Sprintf("%s-%s-%s.yaml", gvk.Kind, m.GetNamespace(), m.GetName()))
544+
fileName := filepath.Join(clusterapi.ArtifactsDir, fmt.Sprintf("%s-%s-%s.yaml", gvk.Kind, m.GetNamespace(), m.GetName()))
548545
objData, err := yaml.Marshal(m)
549546
if err != nil {
550547
errorList = append(errorList, fmt.Errorf("failed to marshal manifest %s: %w", fileName, err))

0 commit comments

Comments
 (0)