github.com/Racer159/jackal@v0.32.7-0.20240401174413-0bd2339e4f2e/src/internal/agent/state/state.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // SPDX-FileCopyrightText: 2021-Present The Jackal Authors
     3  
     4  // Package state provides helpers for interacting with the Jackal agent state.
     5  package state
     6  
     7  import (
     8  	"encoding/json"
     9  	"os"
    10  
    11  	"github.com/Racer159/jackal/src/types"
    12  )
    13  
    14  const jackalStatePath = "/etc/jackal-state/state"
    15  
    16  // GetJackalStateFromAgentPod reads the state json file that was mounted into the agent pods.
    17  func GetJackalStateFromAgentPod() (state *types.JackalState, err error) {
    18  	// Read the state file
    19  	stateFile, err := os.ReadFile(jackalStatePath)
    20  	if err != nil {
    21  		return nil, err
    22  	}
    23  
    24  	// Unmarshal the json file into a Go struct
    25  	return state, json.Unmarshal(stateFile, &state)
    26  }